Error 91

mrinal saha

Board Regular
Joined
Jan 20, 2009
Messages
229
I have this code where in i am getting error 91:

'*************************************************************************************
'****pasting the Book Date, TT and the corresponding deal name as the Heading "*****
'*************************************************************************************
Sub test()
Application.EnableCancelKey = xlDisabled
Dim lr, lastr, lastr1, i As Long
Dim ws As Worksheet
lr = Sheets("Rough").Cells(Rows.Count, 1).End(xlUp).Row

For Each ws In ThisWorkbook.Worksheets
For a = 4 To lr

If Sheets("Rough").Cells(a, 1).Value = "" Then
Exit For
ElseIf Sheets("Rough").Cells(a, 1).Value = ws.Name Then
rownum = Cells(a, 1).Row
GoTo x:
End If
Next a
y: Next ws

x:
lastr = ws.Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Rough").Activate
For i = rownum To lr
If Sheets("Rough").Cells(i, 1).Value <> Sheets("Rough").Cells(i + 1, 1).Value Then
GoTo y:
End If
If Sheets("Rough").Cells(i, 3).Value = Sheets("Rough").Cells(i - 1, 3).Value And _
Sheets("Rough").Cells(i, 4).Value <> Sheets("Rough").Cells(i - 1, 4).Value Then
Sheets("Rough").Activate
Sheets("Rough").Cells(i, 2).Resize(1, 3).Select
Selection.Interior.Color = vbRed
Selection.Copy Destination:=ws.Cells(lastr, 1)

Sheets("User provided Input").Activate
lastr1 = Sheets("User provided Input").UsedRange.Rows.Count
Range("a1:a" & lastr1).CurrentRegion.Select
Selection.Copy Destination:=ws.Cells(lastr + 1, 1)
Sheets("Rough").Activate
End If

If Sheets("Rough").Cells(i, 4).Value <> Sheets("Rough").Cells(i - 1, 4).Value Then
Sheets("Rough").Activate
Sheets("Rough").Cells(i, 2).Resize(1, 3).Select
Selection.Interior.Color = vbRed
Selection.Copy Destination:=ws.Cells(lastr, 1)

Sheets("User provided Input").Activate
lastr1 = Sheets("User provided Input").UsedRange.Rows.Count
Range("a1:a" & lastr1).CurrentRegion.Select
Selection.Copy Destination:=ws.Cells(lastr + 1, 1)
lastr = ws.Cells(Rows.Count, 1).End(xlUp).Row
lastr = lastr + 1
Sheets("Rough").Activate
End If
Next i

End Sub

Thanks,
Mrinal
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Mrinal

That line is outside of your For Each ws .... Next ws loop, so 'ws' does not hold a reference to a worksheet. It only holds a reference to a worksheet inside that loop.
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top