Forum Discussion

ikedalim's avatar
ikedalim
Copper Contributor
Feb 06, 2022
Solved

Move cursor to specific worksheet in Excel

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

  • 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.

4 Replies

    • ikedalim's avatar
      ikedalim
      Copper Contributor
      E3 & E4 are numeric and E5 alphanumeric.
      • 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.

Resources