Wild cards in VBA

Dan71

New Member
Joined
Jul 31, 2006
Messages
48
Good morning all.
I am using this function in VBA

Windows("buying report week 20.xls").select

It works fine but I want to change it so that I can use a wild card as the week number changes. I have tried verious diferent permutations but can't get it to work. I assume it is fairly simple.
Can you help please.
Dan
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi Dan

A good idea would be to set the workbook name as a string variable and also hold the week number in a separate integer variable then pass this to the Windows collection:

Code:
Dim strFile As String, iWeekNum As Integer
iWeekNum = Sheets("Sheet1").Range("A1").Value
strFile = "Buying Report Week" & iWeekNum & ".xls"
Windows(strFile).Activate

You can assign the week value to iWeekNum in a variety of different ways - the above is an example of how you might do so from a worksheet cell.

Hope this helps!

Richard
 
Upvote 0
Thanks Richard, I suppose I wll have to do that. I had hoped that I would not need to put in the week number and keep it really simple. Oh well.
Dan
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,080
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top