Excel VBA Error

k1pp3r

[H]F Junkie
Joined
Jun 16, 2004
Messages
8,339
I'm trying to write a VBA Code in excel to hide rows based off values from another worksheet. I'm have been able to load the values into a variable fine however I am having issues with the range line, Below is my code so far.

Code:
Sub Server1()
'
' Hide Macro
'
Dim var1 As Long
Dim var2 As Long

var1 = Worksheets("RowInfo").Cells(4, "B").Value
var2 = Worksheets("RowInfo").Cells(4, "C").Value

'
Range(var1 & ":" & var2).EntireRow.Hidden = True

'
End Sub

Any Help would be great, when I run the above I get

"Method 'Range' of object'_Global' Failed

I have also tried Rows as well with no luck
 
This worked fine for me in Excel 2007.

Just through the VB into sheet1, changed the name on another sheet to "RowInfo" and changed B4 and C4 to the values I want hidden and it worked on sheet1. B4 = 1, C4 = 1 and it hid the first row in sheet one. B4 = 5, C4 = 10 and it hid rows 5-10.

edit: if I have the sub under the sheet, It applies to that sheet. If I put it under the workbook it applies to whatever tab I have active. It could be due to where ever you have that VB stored.
 
Back
Top