Hi all,
I just started using VBA very recently and haven't had any official training. I've been using the loop below in order to move data from worksheets into a single form that can be printed out, and it's been working perfectly fine until just recently. I'm not sure if something I've done outside of the loop (the subroutine is rather large in order to make the form a one-click button) has somehow destabilized what's in here, and I would greatly appreciate any help.
The "LastRow2 = Cells.Find(What:="Div. 10 SH & N Packinghouse - 1J", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row" statement is causing the macro to stop and move to debugging mode, highlighting the line, but not displaying an error. If I run the macro line by line in debugging mode, there are no errors and the macro runs normally.
Excel 2010
For Each ws2 In Worksheets
Select Case UCase(ws2.Name)
Case "LINE A", "LINE B", "LINE C", "LINE D", "LINE E", "LINE F", "LINE I", "LINE J", "LINE K"
With ws2
'
' Copying and pasting the lines to the sanitation 'master schedule'
'
Sheets(ws2.Name).Activate
LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
str1 = "A2:G" & LastRow
Sheets(WSName).Activate
LastRow2 = Cells.Find(What:="Div. 10 SH & N Packinghouse - 1J", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
long1 = LastRow + LastRow2 - 1
str2 = LastRow2 & ":" & long1
Rows(str2).Insert Shift:=xlDown
str2 = "A" & LastRow2
'
' Pasting the name of the section into the master schedule
'
str3 = ws2.Name & " Equipment"
Range(str2) = str3
str2 = "A" & LastRow2 & ":G" & LastRow2
With Range(str2)
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.MergeCells = True
End With
With Range(str2).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.14996795556505
End With
With Range(str2).Font
.Name = "Calibri"
.Size = 12
End With
LastRow2 = LastRow2 + 1
str2 = "A" & LastRow2
ThisWorkbook.Worksheets(ws2.Name).Range(str1).Copy Destination:=ThisWorkbook.Worksheets(WSName).Range(str2)
End With
End Select
Next ws2
Bookmarks