For each... next (to act on each worksheet)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want my VB application to go through each sheet, check the value in a cell,
and re-name the worksheet according to the value in the cell.

I tried using a "For Each... Next" loop, but VB didn't like using this with
"Sheet" and "ActiveWorkbook" objects.

For Each Sheet In ActiveWorkbook
Select Case Range("A3").Value
Case "aaaa": ActiveSheet.Name = "Company A"
Case "bbbb": ActiveSheet.Name = "Company B"
End Select
Next Sheet

How can I make this work, or structure another loop to do the same action?
Any help is greatly appreciated.
Rgds,
Dan Winterton
 
Hi Dan,

Could it be:

Dim mySheet As Worksheet
For Each mySheet In ActiveWorkbook.Worksheets
Select Case Range("A3").Value
Case "aaaa"
mySheet.Name = "Company A"
Case "bbbb"
mySheet.Name = "Company B"
End Select
Next

I tried Trevors approach ... no go.

Frans
 

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

Back
Top