I want to search in all the tables
Multiple search (search input stored in a array).
Want to msgbox like,
With Selection If .Information(wdWithInTable) = False Then MsgBox "The cursor must be within a table cell.", , "Cursor outside table" Exit Sub
Trial code for two input search
Dim oText As String
Dim oSrch As String
Dim oRng As Range
Dim oCell As Range
Dim oTable As Table
Dim oRow As Row
Dim bText As Boolean
Dim i As Long
Set oTable = Selection.Tables(1)
oText = InputBox(Prompt:="Enter the text", _
Title:="* Search Box *", _
Default:="")
oSrch = InputBox(Prompt:="Enter BD No", _
Title:="* Search Box *", _
Default:="")
For i = 1 To oTable.Rows.Count
bText = False
Set oRow = oTable.Rows(i)
Set oRng = oRow.Cells(1).Range
If InStr(1, oRng.Text, oSrch) > 0 Then
Set oCell = oRow.Cells(4).Range
oCell.End = oCell.End - 1
If Len(oCell) > 0 Then bText = True
oCell.Collapse 0
If bText = True Then
oCell.Text = Chr(32) & oText
Else
oCell.Text = oText
End If
End If
Next i
oSrch = InputBox(Prompt:="Enter 2nd BD No", _
Title:="* Search Box *", _
Default:="")
For i = 1 To oTable.Rows.Count
bText = False
Set oRow = oTable.Rows(i)
Set oRng = oRow.Cells(1).Range
If InStr(1, oRng.Text, oSrch) > 0 Then
Set oCell = oRow.Cells(4).Range
oCell.End = oCell.End - 1
If Len(oCell) > 0 Then bText = True
oCell.Collapse 0
If bText = True Then
oCell.Text = Chr(32) & oText
Else
oCell.Text = oText
End If
End If
Next i
lbl_Exit:
Set oTable = Nothing
Set oRow = Nothing
Set oCell = Nothing
Set oRng = Nothing
Exit Sub
End Sub
|