Please help for macro repair

K0st4din

Active Member
Joined
Feb 8, 2012
Messages
358
Hello,
please someone for help with this macro.
I wrote it manually, but when I open Alt + F11, I get some completely different formula from what I use.
What I'm trying to do is the following:
in the active worksheet from cell O2 to the end (because I do not know where the end will be)
I want to put this formula from cell "O2" and manually - pull down to the end
=COUNTIFS($G$2:$G2; $G2;$J$2:$J2; $J2) - in O2
=COUNTIFS($G$2:$G3; $G3;$J$2:$J3; $J3) - in O3
=COUNTIFS($G$2:$G4; $G4;$J$2:$J4; $J4) - in O4

<tbody>
</tbody>
to the end
When I started to write it manually, the macro itself showed me a completely different formula and I do not know how to do it
Code:
Sub Two_mounths()

    Range("O2").Select
    ActiveCell.FormulaR1C1 = "=COUNTIFS(RC7:RC7,RC7,R2C10:RC10,RC10)" 'this line
    Range("O2").Select
    Selection.AutoFill Destination:=Range("O2:O1231")
    Range("O2:O1231").Select
    Range("O1").Select
    ActiveWorkbook.Save
    Range("O1").Select
End Sub
Thanks in advance to everyone.
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,922
Office Version
  1. 365
Platform
  1. Windows
Assuming that you can use column G to find where the end of the data is, try this:
Code:
Sub Two_months()

    Dim lr As Long
    
'   Find last row with data in column G
    lr = Cells(Rows.Count, "G").End(xlUp).Row

'   Populate formula for all rows
    Range("O2:O" & lr).FormulaR1C1 = "=COUNTIFS(R2C7:RC7,RC7,R2C10:RC10,RC10)"

'   Save workbook
    Activeworkbook.Save

End Sub
 

K0st4din

Active Member
Joined
Feb 8, 2012
Messages
358
Re: SOLVED Please help for macro repair

Thank you so much.
I wish all the best.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,922
Office Version
  1. 365
Platform
  1. Windows
Re: SOLVED Please help for macro repair

You are welcome.
 

Watch MrExcel Video

Forum statistics

Threads
1,114,472
Messages
5,548,228
Members
410,824
Latest member
Bobmn4
Top