Hello, i have created this VBA macro and I would like to add some mathematical operations to it, see code at the bottom for what i'm trying to do but not sure what is the correct way to do it. thanks in advance for your assistance.
VBA Code:
Sub InsertColumnGP()
Dim ws As Worksheet
Set ws = ActiveSheet
'Insert Column to next to the Account number, to the right of Column W
ActiveSheet.Select
Range("AA1").Value = "BU"
Range("AB1").Value = "Amount"
Range("AC1").Value = "Portion"
Range("AD1").Value = "Balance"
Range("AA1:AD1").Interior.Color = ColorConstants.vbYellow
Range("AA1:AD1").Font.Bold = True
Columns("X:X").Insert
Columns("X").NumberFormat = "General"
Columns("G").NumberFormat = "General"
Range("X1").Value = "Sub Account"
Range("X2").Formula = "=Left(W2, 10)"
Range("AB2").Formula = "=VLOOKUP(X2,'[Adaptive Level Hierarchy by Geoff 8.21.20_WA.xlsx]Sheet2'!$A$2:$B$300,2,0)"
With ActiveSheet
.Range("X2").AutoFill .Range("X2:X" & .Cells(.Rows.Count, "W").End(xlUp).Row)
.Range("AB2").AutoFill .Range("AB2:AB" & .Cells(.Rows.Count, "W").End(xlUp).Row)
'add additional columns here
End With
With Range("G2:G" & Cells(Rows.Count, "F").End(xlUp).Row)
.NumberFormat = "General"
.Value = .Value
End With
'Need to add the following mathematical operations to this macro
Range("AC2") = Sum(Y2 - Z2)
Range("AD2") = Sum(N2 / R2)
Range("AE2") = Sum(AC2 * AD2)
End Sub