I am pretty much a beginner in the excel VBA!! Jumping straight to the query
I have condition mentioned in column H, And based on that condition, the data in another column (multiple rows) have to be copied to the word document. I am trying to read the data till the blank from the row which as met the condition and then was planning to get count which could be used to select the range for copying to the word.
But somehow the function doesn't use that After:= command only.
In the attached file, say if the column H5 as Fail. then from the E5 till the blank/Grey Line in the 19th row (E5:E18) have to be copied. and then move on to find the next row in H with Fail condition
Help please!!!
strSearch = "Fail"
dID = 0
With ActiveSheet.Range("H:H")
Set Trng = .Find(strSearch, LookAt:=xlWhole) ' find the first occurence
If Not Trng Is Nothing Then
FirstOcc = Trng.Address
Do
dID = dID + 1
r = Mid(FirstOcc, 4, Len(FirstOcc))
stpRow = .Columns(5).Find(What:="*", After:=.Cells(r, 5), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row occurence'Call the writing to word doc code
Set Trng = .FindNext(Trng)
Loop While Not Trng Is Nothing And Trng.Address <> FirstOcc
End If
End With
Sample Data.xls
Bookmarks