@planbms
As I said there would probably be a formula solution for this as well. This works in E2003, I don't use E2007 and there may be differences.
In your Volume.xls enter the formula into "C4" using CTRL + SHIFT and ENTER to get something like {=INDEX.......))}. If done correctly you will see the curly brackets. Then drag across to "AC3" and down to fill each of the required cells.
I have also improved the speed of the macro. So you now have 2 solutions. Try them and let me know.
Cell formula
=IF(ISNA(INDEX('[ADB.xls]Bordon Sales 2012'!$C$2:$C$274,MATCH($A4&C$3,'[ADB.xls]Bordon Sales 2012'!$A$2:$A$274&'[ADB.xls]Bordon Sales 2012'!$B$2:$B$274,0))),"",INDEX('[ADB.xls]Bordon Sales 2012'!$C$2:$C$274,MATCH($A4&C$3,'[ADB.xls]Bordon Sales 2012'!$A$2:$A$274&'[ADB.xls]Bordon Sales 2012'!$B$2:$B$274,0)))
Macro
Option Explicit
Sub GetCases2()
Dim wsUGVol As Worksheet, wsBorden As Worksheet
Dim iFirstRowVol As Integer
Dim sFirstAddress As String
Dim nRowCount As Long
Dim rUGVol As Range, tblUGVol As Range, rUGItemVol As Range, tblUGItemVol As Range
Dim rUGIdFoundBorden As Range, tblUGBorden As Range, tblUGItemBorden As Range
Dim nMatch As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wsBorden = Workbooks("ADB.xls").Sheets("Bordon Sales 2012")
With wsBorden
Set tblUGBorden = .Range(.Cells(1, "A"), .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, "A")) ''' col A Borden Sales
End With
Set wsUGVol = ThisWorkbook.Sheets("UG VOLUME REPORT APR 2012")
With wsUGVol
iFirstRowVol = 4
Set tblUGVol = .Range(.Cells(iFirstRowVol, "A"), .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, "A")) ''' col A Volume
Set tblUGItemVol = .Range(.Cells(3, "C"), .Cells(3, .Cells(3, .Columns.Count).End(xlToLeft).Column)) ''' row 3 Volume
For Each rUGVol In tblUGVol
nRowCount = 0
Set rUGIdFoundBorden = tblUGBorden.Find(rUGVol, , xlValues, xlWhole, xlRows, xlNext, False) ''' find rows of each customer
If Not rUGIdFoundBorden Is Nothing Then
sFirstAddress = rUGIdFoundBorden.Address
Do
Set rUGIdFoundBorden = tblUGBorden.FindNext(rUGIdFoundBorden)
nRowCount = nRowCount + 1
If rUGIdFoundBorden Is Nothing Then Exit Do
If rUGIdFoundBorden.Address = sFirstAddress Then Exit Do
Loop
With wsBorden ''' set each range
Set tblUGItemBorden = .Range(.Cells(Split(sFirstAddress, "$")(2), "B"), .Cells(Split(sFirstAddress, "$")(2) + nRowCount - 1, "B"))
End With
For Each rUGItemVol In tblUGItemVol
On Error Resume Next
nMatch = 0
nMatch = WorksheetFunction.Match(rUGItemVol, tblUGItemBorden, 0) + 1
If nMatch > 0 Then
.Cells(rUGVol.Row, rUGItemVol.Column) = wsBorden.Cells(Split(sFirstAddress, "$")(2) + nMatch - 2, "C") ''' get value
End If
On Error GoTo 0
Next
End If
Next
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
hth
gmk
Click the * below the post to say thanks and remember to mark the thread as solved if answered satisfactorily.
Bookmarks