[英]Select column and find the value from other cell
我需要選擇“ D:D”列。 然后,我需要在其他單元格的列值中查找。 所以我需要做的是:
一切都在一張紙中,但結果將在另一張紙中使用。 這是為了明天的學校項目。 我整個周末都在努力尋找答案,但是我不能自己做,我的大腦被洗了。
碼:
Columns("B:B").Select
Selection.Find(What:="VA22GU1", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
為什么每個人都想將宏加入公式戰斗?
在單元格J6中鍵入
=OFFSET(D1,MATCH(J5,D:D,0)-1,1,1,1)
現在,在幫助中查找OFFSET
和MATCH
函數。
=INDEX(D:D,MATCH(J5,D:D,0))
同樣的結果,更緊湊,只是表明有多種方法可以給貓皮剝皮。
所以我需要做的是:
1.我在“ J5”單元格中獲得了價值。
2.我需要在D:D中找到該值
3.我需要向右移動一個單元格
4.我需要復制單元格中的所有內容(例如-E2)
5.將其粘貼到“ J6”中
用這個:
'1. Variant with copy method
Sub test()
On Error Resume Next
If [J5].Value <> "" Then
Columns("D:D").Find([J5].Value).Offset(, 1).Copy [J6]
Else
MsgBox "Cell [J5] is empty!"
End If
If Err.Number > 0 Then
MsgBox "Column [D] does not contain search criteria: " & [J5].Value
Err.Clear
End If
End Sub
'2. Variant without copy method
Sub test2()
On Error Resume Next
If [J5].Value <> "" Then
[J6].Value = Columns("D:D").Find([J5].Value).Offset(, 1).Value
Else
MsgBox "Cell [J5] is empty!"
End If
If Err.Number > 0 Then
MsgBox "Column [D] does not contain search criteria: " & [J5].Value
Err.Clear
End If
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.