VBA Add comparative columns between headers

XfortunaX

New Member
Joined
Aug 28, 2014
Messages
28
Hi Forum!

I have the same reptitive task everymorning. In Excel 2010, I have figured out the sort but cannot get my head around adding comparative columns. I am looking to add two columns between different headers. The first column would be titled '$ Change' and contain a formula subtracting column 1 from column 2. The second column would be titled '% Change' and contain another formula.

This is what it looks like now:



This is what I am hoping for it to look like:



I would like to add the peice above onto the bottom of what I already have:
Option Explicit
Sub SortMonths()

Dim FirstDate As String
Dim LastDate As String
Dim LastColumn As Integer

FirstDate = Range("C1")
LastDate = Range("C1").End(xlToRight).Offset(0, -1)

'Rename the current tab
Sheets(1).Name = "CustomerSummary_" & FirstDate & "_" & LastDate

'Move 'Total' over one cell
Selection.End(xlDown).Select
Selection.Cut
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveSheet.Paste

'Name Column B
Range("B1") = "Manufacturer"
Range("C1").Copy
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

'Name the Range of data
Range("C:C").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Name = "RNG"

'Sort the columns
Range("RNG").Select
ActiveWorkbook.Worksheets("CustomerSummary_" & FirstDate & "_" & LastDate).Sort.SortFields.Clear
ActiveWorkbook.Worksheets("CustomerSummary_" & FirstDate & "_" & LastDate).Sort.SortFields.Add Key:=Range("C1:Y1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("CustomerSummary_" & FirstDate & "_" & LastDate).Sort
.SetRange Range("RNG")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With

'Delete AR Adjustments
With ActiveSheet
.AutoFilterMode = False
With Range("B1", Range("B" & Rows.Count).End(xlUp))
.AutoFilter 1, "AR Adjustment CPA*"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With

End Sub

Any help would be awesome.

Thanks,

Tuna
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top