如何在另一个工作表中查找数据并使用 excel VBA 替换相应的值
How to Find the data in another worksheet and place replace the corresponding value using excel VBA
我有两个作品sheet,在第二个作品sheet中我定义了所有参数的唯一名称
在第一个 sheet 中,我只定义了参数名称,在单击“自动填充”按钮时,我希望它去检查首字母缩略词 sheet 中的所有参数名称,如果找到匹配项,它应该替换特定参数的唯一 ID。
任何人都可以告诉我如何使用 excel VBA 实现此目的,我们将不胜感激!
遍历一个找到另一个。
Sub DoIt()
Dim sh As Worksheet, ws As Worksheet
Dim LstRw As Long, rng As Range, c As Range, Frng As Range
Set sh = Sheets("Sheet1") 'Acronym Sheet
Set ws = Sheets("Sheet2")
With sh
LstRw = .Cells(.Rows.Count, "B").End(xlUp).Row
Set rng = .Range("B2:B" & LstRw)
End With
With ws
For Each c In rng.Cells
Set Frng = .Range("C:C").Find(what:=c, lookat:=xlWhole)
If Not Frng Is Nothing Then
Frng.Value = c.Offset(, -1).Value
Else:
End If
Next c
End With
End Sub
我有两个作品sheet,在第二个作品sheet中我定义了所有参数的唯一名称
在第一个 sheet 中,我只定义了参数名称,在单击“自动填充”按钮时,我希望它去检查首字母缩略词 sheet 中的所有参数名称,如果找到匹配项,它应该替换特定参数的唯一 ID。
任何人都可以告诉我如何使用 excel VBA 实现此目的,我们将不胜感激!
遍历一个找到另一个。
Sub DoIt()
Dim sh As Worksheet, ws As Worksheet
Dim LstRw As Long, rng As Range, c As Range, Frng As Range
Set sh = Sheets("Sheet1") 'Acronym Sheet
Set ws = Sheets("Sheet2")
With sh
LstRw = .Cells(.Rows.Count, "B").End(xlUp).Row
Set rng = .Range("B2:B" & LstRw)
End With
With ws
For Each c In rng.Cells
Set Frng = .Range("C:C").Find(what:=c, lookat:=xlWhole)
If Not Frng Is Nothing Then
Frng.Value = c.Offset(, -1).Value
Else:
End If
Next c
End With
End Sub