VBA small code error?

  • Thread starter Thread starter Jo
  • Start date Start date
J

Jo

Hi everone,

Could someone please tell me what is wrong with this small piece of
code, note that Zone5 is cell name ( I am getting error in the 2nd
row):

If Zone5 > 0 Then
Cell(Zone5).Select
Selection.EntireRow.Hidden = True
End If
If Zone4 > 0 Then
Cell("Zone4").Select
Selection.EntireRow.Hidden = True
End If
If Zone3 > 0 Then
Cell("Zone3").Select
Selection.EntireRow.Hidden = True
End If
If Zone2 > 0 Then
Cell("Zone2").Select
Selection.EntireRow.Hidden = True
End If

Thanks,
Jo
 
For starters put Option Explicit at the top of all your modules.
There is no such thing as Cell.
You can do Range("Zone4")

RBS
 
Did you notice Zone5 is not in quotes/








- Show quoted text -

I have it like this now but when I run the macro I get an error:
Method 'Cells' of object '_global' failed!

If Zone5 = 0 Then
Cells("Zone5").Select
Selection.EntireRow.Hidden = True
End If
If Zone4 = 0 Then
Cells("Zone4").Select
Selection.EntireRow.Hidden = True
End If
If Zone3 = 0 Then
Cells("Zone3").Select
Selection.EntireRow.Hidden = True
End If
If Zone2 = 0 Then
Cells("Zone2").Select
Selection.EntireRow.Hidden = True
End If
 
I have it like this now but when I run the macro I get an error:
Method 'Cells' of object '_global' failed!

If Zone5 = 0 Then
Cells("Zone5").Select
Selection.EntireRow.Hidden = True
End If
If Zone4 = 0 Then
Cells("Zone4").Select
Selection.EntireRow.Hidden = True
End If
If Zone3 = 0 Then
Cells("Zone3").Select
Selection.EntireRow.Hidden = True
End If
If Zone2 = 0 Then
Cells("Zone2").Select
Selection.EntireRow.Hidden = True
End If- Hide quoted text -

- Show quoted text -

It is working now with Range instead of Cells. However, I am saying
"If Zone4=0....etc." and while I have Zone4=5, it is hiding that row!?

How come?

Thanks,
Jo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top