I need help troubleshooting some VBA code. The following lines of code are part of a larger procedure in an Excel workbook. Before running the procedure, the workbook is open and it contains four worksheets – “Chase8919,” “T_Export,” “D_Export,” and “BFCU&Chase.” The first step of the code clears the entire contents of worksheet “Chase8919,” then cell A1 is selected. The next two steps repeat this process for worksheets “T_Export” and “D_Export,” respectively. The fourth step goes to worksheet “BFCU&Chase” and selects the cell directly below the last non-empty cell in column A. Then the code goes to End Sub.
When I run the procedure there is no error message. The procedure successfully selects the cell directly below the last non-empty cell in column A of worksheet “BFCU&Chase.” It also successfully deletes the contents of worksheets “Chase8919,” “T_Export,” and “D_Export.” It also successfully selects cell A1 in worksheets “Chase8919” and “T_Export.” But it does not select cell A1 in worksheet “D_Export.” It’s as if it ignores the command, .Range("A1").Value = "" in Step 3. I have attempted to solve the problem by trying both the .Activate and .Select methods in steps 1, 2, and 3 instead of .Range("A1").Value = "" but those result in the error messages, “Run-time error ‘1004’: Activate method of Range class failed” and “Run-time error ‘1004’: Select method of Range class failed.”
Here are the lines code:
' Clear contents and select "A1" in worksheets Chase8919, T_Export, and D_Export, then go back to BFCU&Chase.
' Step 1: Delete all data in worksheet Chase8919
With ThisWorkbook.Worksheets("Chase8919")
.Cells.Clear
.Range("A1").Value = ""
End With
' Step 2: Delete all data in worksheet T_Export
With ThisWorkbook.Worksheets("T_Export")
.Cells.Clear
.Range("A1").Value = ""
End With
' Step 3: Delete all data in worksheet D_Export
With ThisWorkbook.Worksheets("D_Export")
.Cells.Clear
.Range("A1").Value = ""
End With
' Step 4: Select the cell directly below the last non-empty cell in column A of worksheet BFCU&Chase
With ThisWorkbook.Worksheets("BFCU&Chase")
Dim lastRowBFCU As Long
lastRowBFCU = .Cells(.Rows.Count, "A").End(xlUp).Row
.Cells(lastRowBFCU + 1, "A").Select
End With
When I run the procedure there is no error message. The procedure successfully selects the cell directly below the last non-empty cell in column A of worksheet “BFCU&Chase.” It also successfully deletes the contents of worksheets “Chase8919,” “T_Export,” and “D_Export.” It also successfully selects cell A1 in worksheets “Chase8919” and “T_Export.” But it does not select cell A1 in worksheet “D_Export.” It’s as if it ignores the command, .Range("A1").Value = "" in Step 3. I have attempted to solve the problem by trying both the .Activate and .Select methods in steps 1, 2, and 3 instead of .Range("A1").Value = "" but those result in the error messages, “Run-time error ‘1004’: Activate method of Range class failed” and “Run-time error ‘1004’: Select method of Range class failed.”
Here are the lines code:
' Clear contents and select "A1" in worksheets Chase8919, T_Export, and D_Export, then go back to BFCU&Chase.
' Step 1: Delete all data in worksheet Chase8919
With ThisWorkbook.Worksheets("Chase8919")
.Cells.Clear
.Range("A1").Value = ""
End With
' Step 2: Delete all data in worksheet T_Export
With ThisWorkbook.Worksheets("T_Export")
.Cells.Clear
.Range("A1").Value = ""
End With
' Step 3: Delete all data in worksheet D_Export
With ThisWorkbook.Worksheets("D_Export")
.Cells.Clear
.Range("A1").Value = ""
End With
' Step 4: Select the cell directly below the last non-empty cell in column A of worksheet BFCU&Chase
With ThisWorkbook.Worksheets("BFCU&Chase")
Dim lastRowBFCU As Long
lastRowBFCU = .Cells(.Rows.Count, "A").End(xlUp).Row
.Cells(lastRowBFCU + 1, "A").Select
End With