Objective: Write VBA script in one Excel workbook (Default.xls) to open another Excel workbook with a variable name (NFL_*). Then the VBA script in Default will delete several superfluous and merged-cell-type rows (1:12) in NFL. Then it will count the number of populated records in NFL (i.e., number of rows) and delete the last row (because it is not really a record, it is just a cell that sums up one of the columns).
Problem: I can't get the latter part to work - the part about deleting the last "row." I can get it to work if the script is written in the NFL workbook itself, but I can't get it to work with the script written in the Default workbook. Though - I can get the VBA script in the Default workbook to delete rows 1:12 in the NFL workbook. Why won't it work for the latter part?
Problem Restated: The Default workbook has 1 VBA script that performs 2 different actions on another workbook. 1 action - deleting rows 1:12 - works. The second action - deleting the last "row" - does not work.
Thank you in advance for any help!
Sub Chop_FR_NFL()
'Set parameters
Dim wb As Excel.Workbook
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
'Open latest NFL report and delete rows 1:12
Set wb = xlApp.Workbooks.Open("T:\xx\xx\xx\xx\xx\xx\xx\" & "NFL_*", True, False)
wb.Sheets(1).Rows("1:12").Delete
'Delete Total UPB Grand Total cell
Dim UPB As Long
UPB = Range("I" & Rows.Count).End(xlUp).Row
Range("I" & UPB).Select
Selection.Delete
wb.Save
wb.Close
End Sub
1. Right click on any sheet tab in current workbook, then click Select All Sheets from the right-clicking menu. 2. Now all worksheets are selected, if you delete certain rows or ranges in a worksheet, the same rows or ranges in other worksheets are deleted together.
You can't delete sheets from a shared workbook. You can access the following features only if you stop sharing the workbook. You cannot use shared workbooks (shared workbook: A workbook set up to allow multiple users on a network to view and make changes at the same time.
By using the power of Excel Macros, you can automate the process so that Excel will eliminate any and all flagged rows instantaneously. Let's take a real-world example.
This should work:
'...
With wb.Sheets(1)
.Rows("1:12").Delete
.Cells(.Rows.Count, "I").End(xlUp).EntireRow.Delete
End With
'...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With