RuinAerlin
New Member
- Joined
- Apr 8, 2016
- Messages
- 10
Hi All,
I've put a sample of my code below (it repeats for every 6th column up to GW). I get a run time error '91' Object Variable or With Block variable not set when the worksheet does not extend that many columns e.g. on my 3rd tab it only goes up to EN and I debugger highlights the line;
Lastrow = Range("EO:EO").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
What I am trying to do is if the worksheet doesn't extend that far, go to workinprogress.
I've put a sample of my code below (it repeats for every 6th column up to GW). I get a run time error '91' Object Variable or With Block variable not set when the worksheet does not extend that many columns e.g. on my 3rd tab it only goes up to EN and I debugger highlights the line;
Lastrow = Range("EO:EO").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
What I am trying to do is if the worksheet doesn't extend that far, go to workinprogress.
Code:
Dim i As Integer
For i = 2 To Worksheets.Count
Sheets(i).Select
Dim Lastrow As Long
Dim LR As Long
If Not Range("G:G") Is Nothing Then
Lastrow = Range("G:G").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End If
Range("G4:K" & Lastrow).Select
Selection.Copy
LR = Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A" & LR).Offset(1).Select
ActiveSheet.Paste
On Error GoTo workinprogress
If Not Range("M:M") Is Nothing Then
Lastrow = Range("M:M").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End If
Range("M4:Q" & Lastrow).Select
Selection.Copy
LR = Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A" & LR).Offset(1).Select
ActiveSheet.Paste
On Error GoTo workinprogress
workinprogress:
Lastrow = Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A4:E" & Lastrow).Select
Selection.Copy
Sheets("WIP").Select
Lastrow = Range("A:A").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A" & Lastrow).Select
ActiveSheet.Paste
Next i
Last edited: