Select 列并从其他单元格中查找值
Select column and find the value from other cell
我需要 select 列 "D:D" 所以我做到了。
然后我需要在其他单元格的列值中找到。
那么我需要做的是:
- 我在 "J5" 单元格中获得了价值。
- 我需要在 D:D
中找到那个值
- 我需要向右移动一个单元格
- 我需要复制单元格中的所有内容(例如 - E2)
- 粘贴到"J6"
一切都在一个 sheet 中,但结果将用于其他 sheet。这是为了明天的学校项目。我整个周末都在努力寻找答案,但我自己做不到,我的大脑被洗了。
代码:
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
函数。
详细说明@L42评论
=INDEX(D:D,MATCH(J5,D:D,0))
相同的结果,更紧凑,只是表明给猫剥皮的方法不止一种。
So what I need to do:
1.I got value in "J5" cell.
2.I need to find that value in D:D
3.I need to move one cell to right
4.I need to copy everything from cell (for example - E2)
5.Paste it in "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
我需要 select 列 "D:D" 所以我做到了。 然后我需要在其他单元格的列值中找到。 那么我需要做的是:
- 我在 "J5" 单元格中获得了价值。
- 我需要在 D:D 中找到那个值
- 我需要向右移动一个单元格
- 我需要复制单元格中的所有内容(例如 - E2)
- 粘贴到"J6"
一切都在一个 sheet 中,但结果将用于其他 sheet。这是为了明天的学校项目。我整个周末都在努力寻找答案,但我自己做不到,我的大脑被洗了。
代码:
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
函数。
详细说明@L42评论
=INDEX(D:D,MATCH(J5,D:D,0))
相同的结果,更紧凑,只是表明给猫剥皮的方法不止一种。
So what I need to do:
1.I got value in "J5" cell.
2.I need to find that value in D:D
3.I need to move one cell to right
4.I need to copy everything from cell (for example - E2)
5.Paste it in "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