PDA

View Full Version : [SOLVED] Selecting worksheet that is called by macro range



oam
08-13-2015, 04:12 PM
I have a macro that I am working on (see below) and I need to the select the worksheet that is called by a macro. When I run my macro I need to select each tab that “For Each MyCell In myRange” calls.In other words, if “MyCell” called Detroit, Michigan in the list then the next line of code would select the tab labeled “Detroit, Michigan”.

Thank you for your help.



Dim MyCell As Range, myRange As Range
ActiveWorkbook.Sheets("Sheet1").Range ("K2")
Set myRange = Sheets("Sheet1").Range("K2")
Set myRange = Range(myRange, myRange.End(xlDown))
For Each MyCell In myRange

Jacob Hilderbrand
08-13-2015, 05:52 PM
If MyCell has the value you want for the sheet name then it would be:


Sheets(MyCell.Text).Select


Note it is not necessary to select a sheet to work with it so if you just want to make changes on the sheet you can reference is:


With Sheets(MyCell.Text)
.Range("A1").Value = "XXX"
End With

oam
08-13-2015, 07:19 PM
That was the exact items I need to make it work, Thank you for your help!