I wrote a code to search a each of the array variable if presents in each row of a Sheet.Now When the match will be found i need to know what the column number is,where the search string has been found. Any idea how to get that using vb script?
ParentColmnCount=ParentColmnCount-1
IntRow6=2
DataCount=0
Do While objSheet6.Cells(IntRow6,1).Value <> ""
For DataCount=0 to UBound(VMHArray)
If Not objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)) Is Nothing Then
MsgBox(objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)).Columns)
End If
Next
IntRow6=IntRow6+1
Loop
Update:
IntRow6=2
DataCount=0
Do While objSheet6.Cells(IntRow6,1).Value <> ""
For DataCount=0 to UBound(VMHArray)
Set rSearch = objSheet6.Cells(IntRow6,1).EntireRow
Set rFound = rSearch.Find(VMHArray(DataCount))
If Not rFound Is Nothing Then
adrFirst = rFound.Address
Do
MsgBox(IntRow6)
MsgBox(rFound.Column + 1)
MsgBox(adrFirst)
rCol=rFound.Column
objSheet6.Cells(IntRow6,rCol + 2)= objSheet6.Cells(IntRow6,rCol + 5)
Set rFound = rSearch.FindNext(rFound)
Loop Until rFound.Address <> adrFirst And Not rFound Is Nothing
End If
Next
IntRow6=IntRow6+1
Loop
But it seems the control falls into the infinite Loop and continuously giving 21 as its first matched column number.Producing the output as below:
2 33 $AF$2 2 33 $AF$2 2 33 $AF$2 .......
Any idea Why So?
Thanks