Hello,
I am new with VBA/Macros.
I am currently working on a macro and I need the macro to go down an entire column and run everytime the number '2002' is in column R. I have a button set up, but it is currently only working when I am on an active cell. Below is the formula from VBA.
Private Sub CommandButton1_Click()
'
ActiveCell.FormulaR1C1 = _
"=INDEX(R3C3:R8C8,MATCH(RC[-3],R3C1:R8C1,0),MATCH(RC[-2],R1C3:R1C8,0))+IFERROR(INDEX(R3C3:R8C8,MATCH(RC[-2],R3C1:R8C1,0),MATCH(RC[-1],R1C3:R1C8,0)),0)"
ActiveCell.Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A2"), Type:= _
xlFillDefault
ActiveCell.Range("A1:A2").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = _
"=INDEX(R3C3:R8C8,MATCH(R[-1]C[-2],R3C1:R8C1,0),MATCH(RC[-2],R1C3:R1C8,0))+IFERROR(INDEX(R3C3:R8C8,MATCH(RC[-2],R3C1:R8C1,0),MATCH(RC[-1],R1C3:R1C8,0)),0)"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
ActiveCell.Offset(-1, 0).Range("A1").Select
End Sub
Any help will be greatly appreciated!
Thanks,
Sam
I am new with VBA/Macros.
I am currently working on a macro and I need the macro to go down an entire column and run everytime the number '2002' is in column R. I have a button set up, but it is currently only working when I am on an active cell. Below is the formula from VBA.
Private Sub CommandButton1_Click()
'
ActiveCell.FormulaR1C1 = _
"=INDEX(R3C3:R8C8,MATCH(RC[-3],R3C1:R8C1,0),MATCH(RC[-2],R1C3:R1C8,0))+IFERROR(INDEX(R3C3:R8C8,MATCH(RC[-2],R3C1:R8C1,0),MATCH(RC[-1],R1C3:R1C8,0)),0)"
ActiveCell.Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A2"), Type:= _
xlFillDefault
ActiveCell.Range("A1:A2").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.ClearContents
ActiveCell.FormulaR1C1 = _
"=INDEX(R3C3:R8C8,MATCH(R[-1]C[-2],R3C1:R8C1,0),MATCH(RC[-2],R1C3:R1C8,0))+IFERROR(INDEX(R3C3:R8C8,MATCH(RC[-2],R3C1:R8C1,0),MATCH(RC[-1],R1C3:R1C8,0)),0)"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
ActiveCell.Offset(-1, 0).Range("A1").Select
End Sub
Any help will be greatly appreciated!
Thanks,
Sam