SOLVED

Move cursor to specific worksheet in Excel

%3CLINGO-SUB%20id%3D%22lingo-sub-3122545%22%20slang%3D%22en-US%22%3EMove%20cursor%20to%20specific%20worksheet%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3122545%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EIf%20I%20have%20multiple%20worksheets%20(Jan%20to%20Dec%20%26amp%3B%20Main%20page)%20and%20in%20my%20main%20worksheet%2C%20user%20is%20allow%20to%20key%20in%20which%20month's%20worksheet%20to%20go%20to%20and%20error%20message%20popped%20up%20(type%20mismatch)%20when%20running%20the%20VBA%20code%20below.%20Please%20advice%2C%20thanks.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESub%20moveToCell()%3CBR%20%2F%3EDim%20Tday%20As%20Integer%3CBR%20%2F%3EDim%20Tstore%20As%20Integer%3CBR%20%2F%3EDim%20Tmth%20As%20Integer%3CBR%20%2F%3E%3CBR%20%2F%3ETday%20%3D%20Sheets(%22Main%22).Range(%22E3%22).Value%3CBR%20%2F%3ETstore%20%3D%20Sheets(%22Main%22).Range(%22E4%22).Value%3CBR%20%2F%3ETmth%20%3D%20Sheets(%22Main%22).Range(%22E5%22).Value%3CBR%20%2F%3E%3CBR%20%2F%3ESheets(%22Tmth%22).Activate%3CBR%20%2F%3ESheets(%22Tmth%22).Range(Tday%20%26amp%3B%20Tstore).Select%3CBR%20%2F%3EEnd%20Sub%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3122545%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3122633%22%20slang%3D%22en-US%22%3ERe%3A%20Move%20cursor%20to%20specific%20worksheet%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3122633%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1228498%22%20target%3D%22_blank%22%3E%40ikedalim%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20kind%20of%20values%20do%20E3%2C%20E4%20and%20E5%20contain%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3125916%22%20slang%3D%22en-US%22%3ERe%3A%20Move%20cursor%20to%20specific%20worksheet%20in%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3125916%22%20slang%3D%22en-US%22%3EE3%20%26amp%3B%20E4%20are%20numeric%20and%20E5%20alphanumeric.%3C%2FLINGO-BODY%3E
Occasional Contributor

If I have multiple worksheets (Jan to Dec & Main page) and in my main worksheet, user is allow to key in which month's worksheet to go to and error message popped up (type mismatch) when running the VBA code below. Please advice, thanks.

 

Sub moveToCell()
Dim Tday As Integer
Dim Tstore As Integer
Dim Tmth As Integer

Tday = Sheets("Main").Range("E3").Value
Tstore = Sheets("Main").Range("E4").Value
Tmth = Sheets("Main").Range("E5").Value

Sheets("Tmth").Activate
Sheets("Tmth").Range(Tday & Tstore).Select
End Sub

4 Replies

@ikedalim 

What kind of values do E3, E4 and E5 contain?

E3 & E4 are numeric and E5 alphanumeric.
best response confirmed by ikedalim (Occasional Contributor)
Solution

@ikedalim

If Tday (E3) and Tstore (E4) are numeric, Range(Tday & Tstore) is not valid.

For example if E3 = 12 and E4 = 37, Tday & Tstore would be "1237". Range("1237") results in an error.

Yeah, thanks for the advice, I've managed to solve it.