Edit cell value in wrong tab

Asked

Viewed 31 times

0

Guys first good day!

I have a problem because I made a button to edit the value of a certain cell, however my file has 10 different tabs, and it is registering in the wrong tab, as I can do to select the right tab ?

Follow the code below.

Private Sub CommandButton3_Click()

If TxtPrevisto.Text = "" Then
    MsgBox ("Campo Vazio!")
Else
    Range("D2").Value = TxtPrevisto.Text
End If

MetaEHS.LabelEdit = lvwManual

    With MetaEHS


        .SelectedItem.SubItems(3) = TxtPrevisto.Text
        .SelectedItem.SubItems(4) = TxtRealizado.Text


    End With


End Sub
  • See how to take the sheet name and declare a variable, for example as ws, then your code would be ws.Range("D2").Value = TxtPrevisto.Text

  • To learn how to do in Excel click on Record Macro, select the correct tab with the mouse, click on Stop Recording and see the Macro code that Excel recorded. You can learn how to do anything in Excel this way.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.