Sub works great, but I must be on sheet1 before it will add numbers to sheet2. How do I adjust code so that I can run vba no matter what sheet I'm on. This is a hassle because I have 15 of these and switching back and forth is time consuming.
Sub actualAPR()
Dim a As Long, b As Long, c As Long, d As Long, f As Long, g As Long, h As Long, j As Long, k As Long, m As Long
Dim lastrow As Long
Dim I As Integer
a = 0
b = 0
c = 0
d = 0
f = 0
g = 0
h = 0
j = 0
k = 0
m = 0
lastrow = Sheet1.Cells(Rows.Count, 22).End(xlUp).Row
For I = 2 To lastrow
If Cells(I, 2) = "83A00" Then
a = Cells(I, 22) + a
ElseIf Cells(I, 2) = "83B00" Then
b = Cells(I, 22) + b
ElseIf Cells(I, 2) = "83C00" Then
c = Cells(I, 22) + c
ElseIf Cells(I, 2) = "83D00" Then
d = Cells(I, 22) + d
ElseIf Cells(I, 2) = "83F00" Then
f = Cells(I, 22) + f
ElseIf Cells(I, 2) = "83G00" Then
g = Cells(I, 22) + g
ElseIf Cells(I, 2) = "83H00" Then
h = Cells(I, 22) + h
ElseIf Cells(I, 2) = "83J00" Then
j = Cells(I, 22) + j
ElseIf Cells(I, 2) = "83K00" Then
k = Cells(I, 22) + k
ElseIf Cells(I, 2) = "83M00" Then
m = Cells(I, 22) + m
End If
Next I
Sheet9.Select
Range("A3") = "83A00"
Range("N3") = a
Range("A4") = "83B00"
Range("N4") = b
Range("A5") = "83C00"
Range("N5") = c
Range("A6") = "83D00"
Range("N6") = d
Range("A7") = "83F00"
Range("N7") = f
Range("A8") = "83G00"
Range("N8") = g
Range("A9") = "83H00"
Range("N9") = h
Range("A10") = "83J00"
Range("N10") = j
Range("A11") = "83K00"
Range("N11") = k
Range("A12") = "83M00"
Range("N12") = m
End Sub
Sub actualAPR()
Dim a As Long, b As Long, c As Long, d As Long, f As Long, g As Long, h As Long, j As Long, k As Long, m As Long
Dim lastrow As Long
Dim I As Integer
a = 0
b = 0
c = 0
d = 0
f = 0
g = 0
h = 0
j = 0
k = 0
m = 0
lastrow = Sheet1.Cells(Rows.Count, 22).End(xlUp).Row
For I = 2 To lastrow
If Cells(I, 2) = "83A00" Then
a = Cells(I, 22) + a
ElseIf Cells(I, 2) = "83B00" Then
b = Cells(I, 22) + b
ElseIf Cells(I, 2) = "83C00" Then
c = Cells(I, 22) + c
ElseIf Cells(I, 2) = "83D00" Then
d = Cells(I, 22) + d
ElseIf Cells(I, 2) = "83F00" Then
f = Cells(I, 22) + f
ElseIf Cells(I, 2) = "83G00" Then
g = Cells(I, 22) + g
ElseIf Cells(I, 2) = "83H00" Then
h = Cells(I, 22) + h
ElseIf Cells(I, 2) = "83J00" Then
j = Cells(I, 22) + j
ElseIf Cells(I, 2) = "83K00" Then
k = Cells(I, 22) + k
ElseIf Cells(I, 2) = "83M00" Then
m = Cells(I, 22) + m
End If
Next I
Sheet9.Select
Range("A3") = "83A00"
Range("N3") = a
Range("A4") = "83B00"
Range("N4") = b
Range("A5") = "83C00"
Range("N5") = c
Range("A6") = "83D00"
Range("N6") = d
Range("A7") = "83F00"
Range("N7") = f
Range("A8") = "83G00"
Range("N8") = g
Range("A9") = "83H00"
Range("N9") = h
Range("A10") = "83J00"
Range("N10") = j
Range("A11") = "83K00"
Range("N11") = k
Range("A12") = "83M00"
Range("N12") = m
End Sub