Looping through a range

T

Taylorpk

It has been a very long time since I have programmed in Excel. I've got the
general idea, but I'm missing something.

Here's the situation:
I have a information in 2 columns A and B
In column A, if there is something, it is a Worksheet name in the workbook
In column B will be YES or NO indicating whether I should hide the worksheet
or not

Conceptually I know what to do, but I'm struggling with the right commands
and properties.

First I will not know the number of entries -- but I can assume they will
be less 150
I know I want to loop through column B, and if there is a YES, then I should
hide the worksheet that has the name in that row, column B

I thought I had it -- but I'm getting an error. I know this is very simple

sub test()
Dim Rng As Range
Dim Wksname As Worksheet
Dim i As Integer

Sheets("CONTROLLER").Select
Set Rng = Range("A3")
For Each Sheet In Rng
If Rng.Offset(i, 1).Value = "YES" Then <<<< ERROR OCCURS HERE?
Wksname = Rng.Offset(i, 0).Value
If Wksname.Visible = xlSheetVisible Then Wksname.Visible =
xlSheetHidden
End If
i = i + 1
Next Sheet
End Sub

I appreciate the hint
 
D

Don Guillett

UNtested

sub doit()
mc=1
with sheets("Controller")
for i=.cells(rows.count,mc).end(xlup).row to 2
if ucase(.cells(i,2))="YES" then sheets(.cells(i,1)).visible=xlveryhidden
end with
next i
end sub

Sheets("CONTROLLER").Select
 

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

Top