Fix a VBA Type Mismatch When Selecting an Excel Worksheet and Cell
Question details
The user needs to select an Excel worksheet and cell using values stored in VBA variables.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro constructs a worksheet name and cell reference from variables that may contain values from cells E3, E4, and E5.
- Observed behavior
- The macro produces an error when selecting the worksheet and cell. Quoting the variable name refers to a literal worksheet name instead of the variable's value.
Open the workbook in Excel, press Alt+F11 to inspect the macro, and check the values and types stored in the worksheet-name and cell-reference variables. Confirm that the target worksheet exists in the workbook.
Use the worksheet variable and build a valid Range address
Use this approach when the cell address is formed by joining a column letter with row digits.
In the VBA editor, check that Tmth contains the target worksheet name and that joining Tday and Tstore after "A" produces a valid row number. For example, Tday = 123 and Tstore = 7 produce A1237.
In the macro, replace Sheets("Tmth") with a reference to the variable, such as ThisWorkbook.Worksheets(CStr(Tmth)). Quotation marks around Tmth would instead refer to a sheet literally named Tmth.
In the macro, assign the sheet with `Set ws = ThisWorkbook.Worksheets(CStr(Tmth))`, then use `ws.Activate` followed by `ws.Range("A" & Tday & Tstore).Select`. Declare ws as a Worksheet, and run the macro to check the result.

Use Cells when the values are row and column numbers
Use Cells instead of joining an address when Tday and Tstore represent separate row and column numbers.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for an easier move between applications. It does not fix errors in Excel VBA macros.

Frequently Asked Questions
Why does Sheets("Tmth") not use my variable?
Quotation marks make "Tmth" a literal sheet name. Use Worksheets(CStr(Tmth)) to look up the sheet whose name is stored in the variable.
When should I use Range instead of Cells?
Use Range when you have a valid address such as "A1237". Use Cells(row, column) when the values are separate numeric coordinates, such as Cells(3, 4) for D3.
Why can Select fail even if the cell reference is valid?
The target worksheet must be active for its cell to be selected. Activate it with ws.Activate before calling ws.Range(...).Select, or work with the Range directly if selection is unnecessary.
How can I check what is causing the VBA error?
Open the VBA editor with Alt+F11, inspect the variables in the macro, and verify the worksheet name and resulting cell address. A type mismatch, missing worksheet, and invalid address may produce different errors.




