Hi Don,
I got code for my ealier question ages back, from Mr Tom Ogilvy (thanks Mr
Tom)
under caption: VB Code please
I am useing that code and i using fuction formula to show ageing.
but is it possible to insert ageing formula in macro. pl help.
my code as follows.
Sub ProcessData2()
Dim sh1 As Worksheet, sh As Worksheet
Dim Loc_b3, Veh_c3, dtStart As Date, dtend As Date
Dim cell As Range, rng As Range, rw As Long
Dim Frsum As Long, costsum As Long
Set sh1 = Worksheets(1) ' base sheet, where i would show my data gathered
Set sh = Worksheets(Range("b3").Value) ' Worksheets("dat1")
Loc_b3 = sh1.Range("B1")
Veh_c3 = sh1.Range("B2")
dtStart = sh1.Range("D1")
dtend = sh1.Range("D2")
sh1.Range("a7:J500").Clear ' ClearContents
rw = 7
Frsum = 0
costsum = 0
Application.ScreenUpdating = False
' For Each sh In Worksheets
' If sh.Name <> sh1.Name Then
Set rng = sh.Range(sh.Cells(2, 1), sh.Cells(Rows.Count, 1).End(xlUp))
For Each cell In rng
If cell.Offset(0, 2) = Loc_b3 And _
cell.Offset(0, 17) = Veh_c3 And _
cell.Offset(0, 10) >= dtStart And _
cell.Offset(0, 10) <= dtend Then
' sh1.Cells(rw, 1) = cell.Offset(0, 0) ' region
sh1.Cells(rw, 2) = cell.Offset(0, 1) ' branch
sh1.Cells(rw, 3) = cell.Offset(0, 2) ' destination
sh1.Cells(rw, 4) = cell.Offset(0, 5) ' customer name
sh1.Cells(rw, 5) = cell.Offset(0, 9) ' Gcn No
sh1.Cells(rw, 6) = cell.Offset(0, 10) ' Date
sh1.Cells(rw, 7) = cell.Offset(0, 12) ' Lhps No
sh1.Cells(rw, 8) = cell.Offset(0, 17) ' broker name
sh1.Cells(rw, 9) = cell.Offset(0, 29) ' Freight
sh1.Cells(rw, 10) = cell.Offset(0, 36) ' Cost
rw = rw + 1
Frsum = Frsum + cell.Offset(0, 29)
costsum = costsum + cell.Offset(0, 36)
End If
sh1.Cells(rw, 8) = "Total"
sh1.Cells(rw, 9) = Frsum
sh1.Cells(rw, 10) = costsum
Next cell ' cell range (next sheet)
'ActiveCell.Select
' Little formatting
sh1.Range(sh1.Cells(rw, 2), sh1.Cells(rw, 10)).Select
Selection.Interior.ColorIndex = 33
Selection.Font.ColorIndex = 11
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
rw = rw + 1
' End If
Frsum = 0
costsum = 0
'Next sh
Range("e1").Select
Application.ScreenUpdating = True
End Sub
' I am sending my file for you as advised.