Search code examples
vbaexcelexcel-2007

Excel macro add a cell value in a different worksheet based on a specific cell value in the first sheet


Click here to see the picture

Hi, I need someone to help me doing this scenario on my Excel 2007 :)

So here is the scenario :

  • I input QZ0821 in cell B3 (sheet1)
  • I click the CommandButton1 activeX button. (sheet1)

After the commandButton1 is clicked,

  • Add text “Ok” automatically to cell C3 right next to the code (QZ0821) on sheet2 that I’ve input previously on sheet1 as well as if I fill out cell B3 (sheet1) with another code or value.

So whenever I input another code , for example QZ0822 (sheet1), then after I click the button, it will automatically add “Ok” next to cell that contains QZ0822 (sheet2).

Is it possible for me to do that?


Solution

  • Somehting like this?

    Sub lookup()
        Dim strSearch As String
        Dim wks1 As Worksheet
        Dim wks2 As Worksheet
    
        Set wks1 = Sheets("Your Sheet 1") '<--- fill in your sheet name
        Set wks2 = Sheets("Your Sheet 2") '<--- fill in your sheet name
    
        strSearch = wks1.Range("B3").Value
    
        With wks2
            .Columns(2).Find(strSearch).Offset(0, 1).Value = "Ok"
        End With
    End Sub