Using Windows 7, Microsoft Excel 2010 - VBA, I'm trying to create a macro that will format a report & then give me a message box with the totals (or sum) of certain columns that contain specific text. So far I have the macro formatting the report the way I need, & then I have the message box working correctly (only if I manually enter the sum of the needed columns in a separate cell & define the cell as whatever the columns contain), but I would like the macro to sum all values within a column that contains specific text & input the sum in a empty cell, then defining that cell so that it may be used for the message box.
The reports I'm working with contain headers (typically ranging between B1-AZ1 after the initial formatting has been done) such as "expense 1" "expense 2" "expense 3" "7% tax of expense 2" "4% tax of expense 3" "4% tax of expense 1" etc., and within each column are the specific amounts for various clients. An example of these amounts would be "Client 1" "Expense 2" $525.15. Column A has the clients all numbered, ranging anywhere from 1 to 1000+ (depending on the number of clients in a given report.
Given this information (assuming it all makes sense), this is the current code I am using for the formatting & then for the message box as stated above:
'
ActiveCell.Offset(2, 0).Rows("1:1000").EntireRow.Select
Selection.Delete Shift:=xlUp
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Rows("2:3").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Rows("1:1").RowHeight = 38.25
Rows("1:1").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
MsgBox "# of Clients: " & Range("FinalNumClients").Value & vbCrLf & "Total 7% Tax: " & Range("TaxCityOne").Value & vbCrLf & "Total 4% Tax: " & Range("TaxCityTwo").Value, vbOKOnly, "Check Total"
'
End Sub
Unfortunately I have not been able to figure out if VBA can sum all values within multiple columns, depending on if those columns contain specific text such as "Tax" or "Expense," & then enter the sum of all applicable columns (based on if they have the specified text) into an empty cell that could then be defined as needed. If anyone knows a way that this could be done that could work with the current code above I would greatly appreciate it! TIA!
The reports I'm working with contain headers (typically ranging between B1-AZ1 after the initial formatting has been done) such as "expense 1" "expense 2" "expense 3" "7% tax of expense 2" "4% tax of expense 3" "4% tax of expense 1" etc., and within each column are the specific amounts for various clients. An example of these amounts would be "Client 1" "Expense 2" $525.15. Column A has the clients all numbered, ranging anywhere from 1 to 1000+ (depending on the number of clients in a given report.
Given this information (assuming it all makes sense), this is the current code I am using for the formatting & then for the message box as stated above:
'
ActiveCell.Offset(2, 0).Rows("1:1000").EntireRow.Select
Selection.Delete Shift:=xlUp
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Rows("2:3").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Rows("1:1").RowHeight = 38.25
Rows("1:1").Select
With Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
MsgBox "# of Clients: " & Range("FinalNumClients").Value & vbCrLf & "Total 7% Tax: " & Range("TaxCityOne").Value & vbCrLf & "Total 4% Tax: " & Range("TaxCityTwo").Value, vbOKOnly, "Check Total"
'
End Sub
Unfortunately I have not been able to figure out if VBA can sum all values within multiple columns, depending on if those columns contain specific text such as "Tax" or "Expense," & then enter the sum of all applicable columns (based on if they have the specified text) into an empty cell that could then be defined as needed. If anyone knows a way that this could be done that could work with the current code above I would greatly appreciate it! TIA!