devanrose33
New Member
- Joined
- Dec 8, 2015
- Messages
- 6
Hi,
I have a loop inside a Sub that copies and pastes values and cell names into a new workbook. Randomly, the loop stopped working. I haven't adjusted this code or any of the cells that it's looking at, so it's very strange. It's causing the Object error 1004. The code is below and I've highlighted the line that is causing the problem.
With Application
Set wb = Application.Workbooks.Add(1)
Set thisWB = ThisWorkbook
With thisWB.Sheets("Input_Main") 'Copying Row B from Main Input and Pasting into new Excel workbook
Any suggestions?
Thanks in advance!
I have a loop inside a Sub that copies and pastes values and cell names into a new workbook. Randomly, the loop stopped working. I haven't adjusted this code or any of the cells that it's looking at, so it's very strange. It's causing the Object error 1004. The code is below and I've highlighted the line that is causing the problem.
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
.Calculation = xlCalculationManual
End WithSet wb = Application.Workbooks.Add(1)
Set thisWB = ThisWorkbook
With thisWB.Sheets("Input_Main") 'Copying Row B from Main Input and Pasting into new Excel workbook
wb.Sheets(1).Columns(1).NumberFormat = "@"
For i = 5 To INPUTEnd + 5 'INPUTEnd = 366
.Range("B" & i).Copy
wb.Sheets(1).Range("A" & count).PasteSpecial xlValues '***
If IsRangeName(.Range("B" & i).Address) Then 'If named range then copy the range name to export file
wb.Sheets(1).Range("A" & count).Name = .Range("B" & i).Name.Name & "_tmp"
count = count + 1
End If
Next i
End withAny suggestions?
Thanks in advance!