0

My macro works with a large (10,000 row) spreadsheet to sort, delete, paste, and resave the data. When I get to the "Sheets.Select" and "Sheets.Move" of the new spreadsheet I am trying to create, the code crashes.

When I step through the code, the macro works. If I put in a "Debug.Assert False" command at the beginning of the code, the command box does come up, and I click "Continue" and the macro runs correctly to the end. Can't debug because the step-through works fine.

'Rename OEM List (2)

Dim QuoteNo As String
Sheets("OEM List (2)").Select
Range("B11").Select
QuoteNo = ActiveCell.Value
ActiveSheet.Name = QuoteNo & " - OEM List"

Range("A1").Select

Dim wsA As Worksheet
Dim strName As String
Dim strFile As String
Dim strPathFile As String

Set wsA = ActiveSheet

'Format all rows

Rows("17:8042").Select
Rows("17:8042").EntireRow.AutoFit

'Export with no copy newly named "Quote *"

'MACRO EITHER CRAHSHES HERE

Sheets(QuoteNo & " - OEM List").Select

'OR HERE

Sheets(QuoteNo & " - OEM List").Move

'OR HERE

The macro is supposed to take the newly created and named spreadsheet, move it to a new workbook, save the workbook with a saved name, close this new workbook, re-save the original workbook and end.

When I step through the code, the macro works. If I put in a "Debug.Assert False" command and run the macro, when the code gets to the .Select or the .Move lines, the command box comes up, I click "Continue" and the macro runs correctly to the end. Can't debug because the step-through works fine.

'Rename OEM List (2)

Dim QuoteNo As String
Sheets("OEM List (2)").Select
Range("B11").Select
QuoteNo = ActiveCell.Value
ActiveSheet.Name = QuoteNo & " - OEM List"

Range("A1").Select

Rows("17:8042").Select
Rows("17:8042").EntireRow.AutoFit

Dim wsA As Worksheet
Dim strName As String
Dim strFile As String
Dim strPathFile As String

Set wsA = ActiveSheet

'Export with no copy newly named "Quote *"

'THE MACRO EITHER CRASHES HERE,

Sheets(QuoteNo & " - OEM List").Select

'OR HERE

Sheets(QuoteNo & " - OEM List").Move

The macro is supposed to take the newly created and named spreadsheet, move it to a new workbook, save the workbook with a saved name, close this new workbook, re-save the original workbook and end.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
JackDD
  • 1
  • 1
  • 3
    Additionally, I would suggest reading [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) – Marcucciboy2 Aug 07 '19 at 18:23
  • 2
    @Marcucciboy2 if you don't specify where to move it to, the sheet gets moved to a new workbook. But I completely and 100% agree with avoiding `Select`, can't emphasize that enough. – BigBen Aug 07 '19 at 18:29

0 Answers0