Macro Run Time Error 91

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,163
I was supplied this code as an answer to a post at:
http://www.ozgrid.com/forum/showthread.php?t=73583

Code:
Sub asdf() 
    Dim c As  Range 
    Dim x As Long 
    Dim y As Integer 
     
    Set c = Columns("A:B"). Find(" Total", lookat:=xlWhole) 
    x = c.Row 
    For y = 15 To 4  Step -1 
        If Cells(x, y) = 0 Then Columns(y).Delete 
    Next y 
End Sub

However, it errors out at
Code:
x = c.Row
Saying "object variable or With block variable not set"
I have xl2000. Could this be the problem?

With the code I'm trying to locate my "Total" row. Then delete all columns from D:O with a value of zero. An example sheet is supplied at the link.
Thank you very much for your time and help.
 
Are you sure all you added to your code was End If?

Norie,
It's not my code. Its Brian's code. He accidentally missed an End If part.
All I had to do was add that and his code worked real awesome like. I wasn't sure why because as you pointed out it wasn't much different. He explained why, but since I'm just a rookie at vba, and I'm sure it's obvious because I need lots of help, I don't know if I follow his explanation. But it works. :LOL:
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Untested but should work in theory

Code:
Sub asdf() 
Dim C as Range, x as Long, y as Long 

Set C = Columns("A:B").Find("Total", lookat:=xlWhole) 
If Not C is Nothing then 
    x = C.Row 
    For y = 15 To 4 Step -1 
        If Cells(7, y) > Format(Now(), "mm") And Cells(x, y) = 0 Then Columns(y).Delete
    Next y 
End if 

End Sub
 
Upvote 0
Just now went and looked at the other post and realized there is a very similar post there.

Code:
Sub asdf() 
Dim C as Range, x as Long, y as Long 

Set C = Columns("A:B").Find("Total", lookat:=xlWhole) 
If Not C is Nothing then 
    x = C.Row 
    For y = 15 To 4 Step -1 
        If Cells(7, y) > Format(Now(), "mm") Then
            If Cells(x, y) = 0 Then Columns(y).Delete
        End If
    Next y 
End if 

End Sub

He just chose to break out the if statements.
 
Upvote 0
THank you for your reply and for checking the other forum.
The code however, errors out with a compile error saying wrong number of arguments or invalid property assignment. It highlights the word "Format".
 
Upvote 0

Forum statistics

Threads
1,215,688
Messages
6,126,209
Members
449,299
Latest member
KatieTrev

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