根据映射替换列中的值
Replacing values in a column according to a map
我在 Excel sheet 中有两列 A 和 B,类似于以下内容:-
A B
1 1
2 2
3 4
4 5
5 6
6 7
7 8
8 10
9 11
10 12
11 13
12 15
13 16
14 17
15 18
现在,在另一个 sheet 中,我有一列 B 值,我想将它们 'map' 到它们对应的 A 值。通过 'map' 它们,我的意思是用第一个 sheet 中与其相邻的 A 值替换 B 值。我该怎么做?
选项 1)
在 sheet2 的 C 列中,你想要你的结果,假设你的 B 数据在 D 列中只是为了混淆。
=INDEX(SHEET1!$A:$A,MATCH(D2,SHEET1!$B:$B,0))
选项 2)
相同的设置,但让我们使用 LOOKUP 函数
=LOOKUP(D2,SHEET1!$B:$B,SHEET1!$A:$A)
与 Sheet1 喜欢:
和Sheet2喜欢:
运行 这个简短的宏:
Sub Translate()
Dim B As Range, RangeToFix As Range, r As Range
Dim fnd As Range
Set B = Sheets("Sheet1").Range("B1:B15")
Set RangeToFix = Sheets("Sheet2").Range("B1:B11")
For Each r In RangeToFix
Set fnd = B.Find(What:=r.Value, After:=B(1))
If fnd Is Nothing Then
r.Offset(0, 1).Value = "not found"
Else
r.Value = fnd.Offset(0, -1).Value
End If
Next r
End Sub
将在 Sheet2 中生成:
这会就地 "translation"。
我在 Excel sheet 中有两列 A 和 B,类似于以下内容:-
A B
1 1
2 2
3 4
4 5
5 6
6 7
7 8
8 10
9 11
10 12
11 13
12 15
13 16
14 17
15 18
现在,在另一个 sheet 中,我有一列 B 值,我想将它们 'map' 到它们对应的 A 值。通过 'map' 它们,我的意思是用第一个 sheet 中与其相邻的 A 值替换 B 值。我该怎么做?
选项 1)
在 sheet2 的 C 列中,你想要你的结果,假设你的 B 数据在 D 列中只是为了混淆。
=INDEX(SHEET1!$A:$A,MATCH(D2,SHEET1!$B:$B,0))
选项 2)
相同的设置,但让我们使用 LOOKUP 函数
=LOOKUP(D2,SHEET1!$B:$B,SHEET1!$A:$A)
与 Sheet1 喜欢:
和Sheet2喜欢:
运行 这个简短的宏:
Sub Translate()
Dim B As Range, RangeToFix As Range, r As Range
Dim fnd As Range
Set B = Sheets("Sheet1").Range("B1:B15")
Set RangeToFix = Sheets("Sheet2").Range("B1:B11")
For Each r In RangeToFix
Set fnd = B.Find(What:=r.Value, After:=B(1))
If fnd Is Nothing Then
r.Offset(0, 1).Value = "not found"
Else
r.Value = fnd.Offset(0, -1).Value
End If
Next r
End Sub
将在 Sheet2 中生成:
这会就地 "translation"。