by SkxHV2hpe » Thu, 28 Feb 2008 04:37:02
evised Code, adds a line to create last row variable and
replaces the row reference in original line nine with the
variable, creating a dynamic range.
Sub CheckData()
Dim c As Range
Dim findC As Variant
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUP).Row
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Windows("Report.xls").Activate '<-- My report
For Each c In ActiveSheet.Range("A2:A" & lastRow)
If Not c Is Nothing Then
Windows("SourceDoc.xls").Activate '<-- My document to be checked
Set findC = Worksheets("Sheet1").Cells _
.Find(c.Value, LookIn:=xlValues)
If Not findC Is Nothing Then
Windows("Report.xls").Activate
ActiveSheet.Range("I" & c.Row).Cells.Value = "20/02/2008"
End If
End If
Next
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
The following snippet will search the source doc for the
value of each cell in column of the target document and
if a match is found, will copy column B value of source
doc to column I of the target doc on the same row as the
item being queried. Assuming Report.xls is the target
workbook and sheet1 is the active sheet in both
workbooks. It the assumtion is incorrect then change
accordingly. Also assumes there will be only one occurence
of any item in either workbook's sheet1.
Dim c As Range
Dim dt As Range
lastRow = Workbooks("Report.xls").Sheets(1) _
.Cells(Rows.Count, 1).End(xlUP).Row
lstRow2 = Workbooks("SourceDoc.xls").Sheets(1) _
.Cells(Rows.Count, 1).End(xlUp).Row
fRng = Workbooks("Report.xls").Sheets(1)
sRng = Workbooks("SourceDoc.xls")
For Each c In fRng.Range("A2:A" & lastRow)
If Not c Is Nothing Then
For Each dt In sRng.Sheets(1).Range("A2:A" & lstRow2)
If Not dt Is Nothing Then
If dt.Value = c.Value Then
dt.Offset(0 1).Copy fRng.Range("I" & c.Row)
Exit For
End If
End If
Next
End If
Next
I did not know where you wanted to insert this, or if you wanted to
insert it, in the other code, so I will let you decide that. I did
not test it so if you get errors post back. Eliminate any duplicate
statements like Dim c and lastRow declarations when you insert.
"DDawson" wrote: