Please help for macro repair

K0st4din

Active Member
Joined
Feb 8, 2012
Messages
412
Office Version
  1. 2013
  2. 2011
  3. 2010
  4. 2007
Platform
  1. Windows
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.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,304
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
412
Office Version
  1. 2013
  2. 2011
  3. 2010
  4. 2007
Platform
  1. Windows
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
63,304
Office Version
  1. 365
Platform
  1. Windows
Re: SOLVED Please help for macro repair

You are welcome.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,116
Messages
5,835,476
Members
430,358
Latest member
zzc1128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top