I'm trying to do a sumif formula, but am having difficulties. First, I want to move to the cell next to the last cell on row A3. My first part seems to accomplish that. Second, I want to do a sumif formula (sumif(range,criteria, sum_range)) where the value lands on the active cell. However, I can't seem to get the formual to work. My number of columns can change so I can't have that be constant. I want the range to be from G1 through the last active column (i.e. JW1 or some other value instead of JW), my criteria to be the letter "M" and my sum range to be G3 through the last active column, which would match the last active column in my first range. Then, I want to autofill down to the last row, where my first range is locked, but the sum range isn't locked.
Sub Sumif()
Dim lastColumn As Range
Dim NextlastColumn As Range
lastColumn = Range("G1" & Column.Count).End(xlToRight).Column
NextlastColumn = Range("G3" & Column.Count).End(xlToRight).Column
Range("A3").Select
Selection.End(xlToRight).Offset(, 1).Select
ActiveCell.Formula = "=SUMIF(lastColumn,{"M"}, NextlastColumn))"
End Sub