Hello,
I am new to VBA and I am attempting to write a macro that will subtract 2 cells and record the info in a 3rd cell. I would need the formula to continue in each row until the last line of info. It starts J2 - H3, then on the next row would be J3 - H4 and so on.This would repeat on multiple sheets within a workbook. The big problem is there is different formula in J2 that must remain untouched. I came up with the macro below but it still starts in J2 and overwrites the formula there. I just need this process to start on J3. Any help would be greatly appreciated.
Sub ONHAND2()
Dim ws As Worksheet
Dim Lastrow As Long
With ActiveSheet
For Each ws In ActiveWorkbook.Worksheets
Sheets.Select
ws.Activate
LastRowColumnH = Cells(Rows.Count, 1).End(xlUp).row
Firstrow = J3
If ActiveCell.row < 3 Then Exit Sub
If ActiveCell.row > 2 Then
Range("J3:J"" & LastRowColumnH).End(xlDown).Formula = "=J2-H3"
End If
Next
End With
End Sub
If it helps at all this macro seems to work when there is multiple lines of info, but when there is only 1 line it starts J2 - J3 in the actual cell J2 and displays incorrect info.
Bookmarks