MemphisVBA
Technical User
I saw PVH's response to thread705-997479
and I am trying to do something very similar...
Here is the macro that I am trying to run once Access creates the workbook
My report in Access is "Fuel Card" - which is driven by "qryFuelCardReport"
Any help or suggestions is greatly appreciated.
and I am trying to do something very similar...
Here is the macro that I am trying to run once Access creates the workbook
Code:
Option Explicit
Sub FuelCard_Report()
'
Cells.Select
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
Rows("1:1").Select
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("C1").Select
ActiveCell.FormulaR1C1 = "Trans Date"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Trans Time"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Address"
Range("H1").Select
ActiveCell.FormulaR1C1 = "SL/ST"
Range("J1").Select
ActiveCell.FormulaR1C1 = "Miles Driven"
Range("L1").Select
ActiveCell.FormulaR1C1 = "Gal Purchased"
Range("M1").Select
ActiveCell.FormulaR1C1 = "Price Per Gal"
Range("N1").Select
ActiveCell.FormulaR1C1 = "Total Cost"
Range("O1").Select
ActiveCell.FormulaR1C1 = "Cost Per Mile"
Range("A1:O1").Select
Range("O1").Activate
With Selection.Interior
.ColorIndex = 33
.Pattern = xlSolid
End With
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Columns("D:D").Select
Selection.NumberFormat = "[$-409]h:mm:ss AM/PM;@"
Columns("H:H").Select
Selection.NumberFormat = "0000"
Range("A1:O198").Select
Range("C10").Activate
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Columns("A:A").EntireColumn.AutoFit
Range("L3").Select
Columns("L:L").ColumnWidth = 14.14
Columns("J:J").ColumnWidth = 10.57
Columns("D:D").ColumnWidth = 10.43
Columns("M:M").ColumnWidth = 11.29
Columns("N:N").ColumnWidth = 9.43
Rows("1:1").Select
Range("C1").Activate
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("I:I").ColumnWidth = 9.43
Columns("L:L").ColumnWidth = 10.57
'make Consecutive days red (thanks PVH!)
Dim r As Long
Range("C:C").Font.ColorIndex = xlColorIndexAutomatic
r = 3
While Cells(r, "C") <> ""
If Cells(r, "C") = Cells(r - 1, "C") Then
Cells(r, "C").Font.ColorIndex = 3
Cells(r - 1, "C").Font.ColorIndex = 3
End If
r = r + 1
Wend
' subtotal by VIN
Range("A1:O198").Select
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(13, 14, 15 _
), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Range("A1").Select
End Sub
My report in Access is "Fuel Card" - which is driven by "qryFuelCardReport"
Any help or suggestions is greatly appreciated.