I get this error and im not sure if my code works for autofilling the range "G" "I" "O" and "P".
Any help is apperciated
Sub Purchasing()
'
' Purchasing Macro
'
' Keyboard Shortcut: Ctrl+Shift+Z
'
Cells.Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A2:A121") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:P1000")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Dim rFndResult1 As Range
Set rFndResult1 = Range("A1:AZ1").Find("(Water)", , xlValues, xlWhole)
If Not rFndResult1 Is Nothing Then
Columns(rFndResult1.Column + 1).Insert
Cells(1, rFndResult1.Column + 1).Value = Format(Now(), "JJmmddyy")
End If
Dim rFndResult2 As Range
Set rFndResult2 = Range("A1:AZ1").Find("(Water)", , xlValues, xlWhole)
If Not rFndResult2 Is Nothing Then
Columns(rFndResult2.Column + 2).Insert
Cells(1, rFndResult2.Column + 2).Value = "plts"
End If
Range("G2").Select
ActiveCell.FormulaR1C1 = "=RC[-3]*RC[1]"
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G3")
Range("I2").Select
ActiveCell.FormulaR1C1 = "=RC[-6]+RC[-3]+RC[-2]-RC[1]"
Range("I2").Select
Selection.AutoFill Destination:=Range("I2:I3")
Dim rFndResult As Range
Set rFndResult = Range("A1:AZ1").Find("Days", , xlValues, xlWhole)
If Not rFndResult Is Nothing Then
Columns(rFndResult.Column + 1).Insert
Cells(1, rFndResult.Column + 1).Value = "NDAYS"
End If
Range("O2").Select
ActiveCell.FormulaR1C1 = "=RC[-6]/(RC[-3]/90)"
Dim rFnndResult3 As Range
Set rFndResult3 = Range("A1:AZ1").Find("NDAYS", , xlValues, xlWhole)
If Not rFndResult3 Is Nothing Then
Columns(rFndResult3.Column + 1).Insert
Cells(1, rFndResult3.Column + 1).Value = "weight"
With Sheets("Sheet1")
Dim LastRow As Long
LastRow = Range("p" & Rows.Count).End(xlUp).Row
With Range("P2")
.FormulaR1C1 = "=RC[-11]*RC[-9]"
.AutoFill Destination:=Range("P1:P" & LastRow)
End With
End Sub
Bookmarks