简体   繁体   English

Excel宏根据第一张工作表中的特定单元格值在其他工作表中添加单元格值

[英]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 :) 嗨,我需要有人来帮助我在Excel 2007上进行这种情况:)

So here is the scenario : 所以这是场景:

  • I input QZ0821 in cell B3 (sheet1) 我在单元格B3 (sheet1)中输入了QZ0821
  • I click the CommandButton1 activeX button. 我单击CommandButton1 activeX按钮。 (sheet1) (表Sheet 1)

After the commandButton1 is clicked , 单击commandButton1后,

  • 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. 将文本“ Ok ”自动添加到单元格C3中,紧挨我先前在sheet1上输入的sheet2上的代码( QZ0821 )旁边,以及是否用其他代码或值填充单元格B3(sheet1)。

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). 因此,每当我输入另一个代码,例如QZ0822(sheet1),然后单击按钮后,它将自动在包含QZ0822(sheet2)的单元格旁边添加“确定”。

Is it possible for me to do that? 我可以这样做吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM