Hi,
In my excel workbook i have A-F columns in each worksheet.
Column D has value(assume "Arc") which needs to be searched in each worksheet starting from Sheet2.If "Arc" is found then that entire row will be copied to Sheet 1. This needs to be done for all the worksheets in workbook.
Column F is Status column which have values (Open,Closed or blank).
So my macro should be:
Copy only those rows to Sheet1 where "Arc" is found and its status is not "Closed" (ie. it can be Open or blank)
Hope this description helps.
I have written the below code which will copy data from different sheets to Tracker sheet based on input given.
In column F (Status), i dont want to show rows whose status is Closed.(i.e only open and "" rows should be displayed in the tracker) but i am getting a message pop-up as "
Object variable or with block variable not set" at this line:
If Not fRng Is Nothing And LCase(fRng.Offset(0, 2)) <> "closed" Then
Can anyone help me to resolve it?
Sub vLookUp()
Dim shM As Worksheet, sh As Worksheet, status As String, sName As Variant, rng As Range, fRng As Range, fVal As String
Dim lr As Long
Set shM = Sheets("Tracker")
fVal = InputBox("Enter Action Item", "VALUE TO FIND")
If fVal = "" Then
Exit Sub
End If
For Each sh In ThisWorkbook.Sheets
sName = sh.Name
If sh.Name <> shM.Name Then
Set rng = Intersect(sh.Range("D : D"), sh.UsedRange)
Set fRng = rng.Find(fVal, LookIn:=xlValues, LookAt:=xlWhole)
If Not fRng Is Nothing And LCase(fRng.Offset(0, 2)) <> "closed" Then
fAdr = fRng.Address
Do
lr = shM.Cells(Rows.Count, 4).End(xlUp).Row + 1
fRng.EntireRow.Copy shM.Cells(lr, 1)
shM.Cells(lr, 1).Value = sName
fRng.Value = fVal
Set fRng = rng.FindNext(fRng)
Loop While fRng.Address <> fAdr
End If
End If
Next
End Sub
Regards,
Archies