Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select a worksheet based on text in cell A1?? 1

Status
Not open for further replies.

rlee16

Technical User
Jan 19, 2003
44
HK
I am running a batch file, where I open up files which have 7 worksheets on average. I want to make changes on a particular sheet where in cell A1 contains the text "xxxxxx detailed". (where xxxxxx represents varying text).

I would like my code to open up the file; search through Cell A1 on each wkshts and when it finds the one with "detailed" on it, to Select that wksht.


Do Until mcol = z

Workbooks.Open Filename:="S:\Data\1Comp\" & Cells(603, mcol), _
UpdateLinks:=0
MyName1 = ActiveWorkbook.Name

'Search thru wkshts
'If Range("a1") = ****detailed??? Then
Current Worksheet.Select

Thanks for the help.

Richard
 
Hi Richard,

Try ...

Code:
Dim wks as Worksheet

For Each wks In ActiveWorkbook.Worksheets

    If Right(wks.[A1], 8) = "detailed" Then
Code:
        ' Do your stuff here
Code:
    End If

Next

Enjoy,
Tony
 
Tony,

I have added in the code by it seems to skip right over the If Right(wks.[A1], 8) = "detailed" part.

Is the [A1] coding correct?

is there a way to not use the trim function, instead use a find? or does the *.* syntax work in VBA?

Thanks

Richard
 
Hi Richard,

When you say skips right over do you mean it is entirely bypassed (the loop doesn't even run once)? Or does it just not match the cell?

The [A1] format should be fine but if you want to code wks.Range("A1") as per your original post that's good too.

You can say If wks.[A1] Like "*detailed" if you prefer.

Enjoy,
Tony
 
Thanks Tony,

I was using F8 to run through the program and I didn't let it run through the loop once.

it works great!

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top