References Excel Sheets Named As Numbers

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
189
I'm building an Access application that needs to populate an Excel workbook. The sheets of the workbooks are named numerically as the days of the month ("1", "2", "3" through "31").

I'm incrementally increasing a variable through a loop to identify each sheet, but am having trouble referencing the Excel Sheet, for example:

wkbk.Sheets("1") gives me the sheet entitled "1"
wkbk.Sheets(1) gives me the left-most sheet in the workbook.

If x = 1, How do I reference wkbk.Sheets("1")?

Thank You in Advance for your help and time.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,

You could test

Code:
Sheets("" & x & "")

HTH
 
Upvote 0
Sheets can be referenced using index or name, depending on whether you provide a number or string value.

Code:
Sub Foo()
Dim x As Long
x = 1
Debug.Print Sheets(x).Name
Debug.Print Sheets(CStr(x)).Name
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,704
Messages
6,161,390
Members
451,701
Latest member
ckrings

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