fari1
Active Member
- Joined
- May 29, 2011
- Messages
- 362
i've a code that finds a particular text occurances in the whole sheet and give results in another sheet.
i want to find two more text strings but unable to mould it to find, tried too many ways, but errors, can anybody guide how would this code be amended if a want to search notes and balance as well alongwith consolidated.
Thanks
i want to find two more text strings but unable to mould it to find, tried too many ways, but errors, can anybody guide how would this code be amended if a want to search notes and balance as well alongwith consolidated.
Thanks
Code:
Sub findTEXT()
Static wsSrc As Worksheet: Set wsSrc = ActiveWorkbook.Sheets("Sheet2")
Static wsDst As Worksheet: Set wsDst = ActiveWorkbook.Sheets("Sheet3")
Static StartAddress As String
Dim rngFnd As Range
Dim rngAll As Range
Dim allfound As Boolean
Set rngFnd = wsSrc.UsedRange.Find("consolidated")
If Not rngFnd Is Nothing Then StartAddress = rngFnd.Address
While Not rngFnd Is Nothing And allfound = False
If RowLen(wsSrc, rngFnd) < 50 And rngAll Is Nothing Then Set rngAll = rngFnd
Set rngFnd = wsSrc.UsedRange.Find("consolidated", rngFnd)
If RowLen(wsSrc, rngFnd) < 50 Then
If rngAll Is Nothing Then Set rngAll = rngFnd
If Intersect(rngAll, rngFnd) Is Nothing _
And Intersect(rngAll.EntireRow, rngFnd) Is Nothing _
Then Set rngAll = Union(rngAll, rngFnd)
End If
If rngFnd.Address = StartAddress Then allfound = True
Wend
wsDst.Range("A" & wsDst.UsedRange.Offset(, 1).Find(what:="*", after:=wsDst.[B1], searchdirection:=xlPrevious).Row + 1).Value = wsSrc.Range("A1").Value
If Not rngAll Is Nothing Then Intersect(rngAll.EntireRow, rngAll.Worksheet.Range("A:Z")).Copy wsDst.Range("B" & wsDst.UsedRange.Offset(, 1).Find(what:="*", after:=wsDst.[B1], searchdirection:=xlPrevious).Row + 1)
End Sub
Function RowLen(ws As Worksheet, rng As Range) As Long
Dim c As Range
For Each c In Intersect(rng.EntireRow, ws.UsedRange)
RowLen = RowLen + Len(c.Text)
Next c
End Function