使用 VBA 将 WORD TABLE 中的搜索数据提取到 EXCEL
EXTRACT the search data in the WORD TABLE to EXCEL using VBA
如何使用宏提取单词 table 中的搜索数据。
示例 TABLE:
Name Age Sex Address Number
Adam 18 Male Manila 1
Rina 18 Female Manila 2
我想在搜索Rina时得到号码
谁能帮我解决这个问题。谢谢
这是一个非常基本的问题,如果您在 google 上搜索,您会找到很多答案。但是,您可以通过多种方式进行。使用 VLookup()
如下所示。
=VLOOKUP(G2,A2:E3,5)
您可以使用 Index()/Match()
组合,例如-
=INDEX(E2:E3,MATCH(G2,A2:A3,0))
如果你有Office365那么可以使用XLOOKUP()
=XLOOKUP(G2,A2:A3,E2:E3)
例如:
Sub Demo()
Application.ScreenUpdating = False
Dim StrOut As String
With ActiveDocument.Tables(1).Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = InputBox("What is the Name to Find")
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = True
.Execute
End With
If .Find.Found = True Then
MsgBox "The Number is: " & Split(.Rows(1).Cells(5).Range.Text, vbCr)(0)
End If
End With
Application.ScreenUpdating = True
End Sub
如何使用宏提取单词 table 中的搜索数据。
示例 TABLE:
Name Age Sex Address Number
Adam 18 Male Manila 1
Rina 18 Female Manila 2
我想在搜索Rina时得到号码
谁能帮我解决这个问题。谢谢
这是一个非常基本的问题,如果您在 google 上搜索,您会找到很多答案。但是,您可以通过多种方式进行。使用 VLookup()
如下所示。
=VLOOKUP(G2,A2:E3,5)
您可以使用 Index()/Match()
组合,例如-
=INDEX(E2:E3,MATCH(G2,A2:A3,0))
如果你有Office365那么可以使用XLOOKUP()
=XLOOKUP(G2,A2:A3,E2:E3)
例如:
Sub Demo()
Application.ScreenUpdating = False
Dim StrOut As String
With ActiveDocument.Tables(1).Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = InputBox("What is the Name to Find")
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = True
.Execute
End With
If .Find.Found = True Then
MsgBox "The Number is: " & Split(.Rows(1).Cells(5).Range.Text, vbCr)(0)
End If
End With
Application.ScreenUpdating = True
End Sub