Please help for macro repair

K0st4din

Well-known Member
Joined
Feb 8, 2012
Messages
501
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 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
[TABLE="width: 514"]
<tbody>[TR]
[TD] =COUNTIFS($G$2:$G2; $G2;$J$2:$J2; $J2) - in O2[/TD]
[/TR]
[TR]
[TD] =COUNTIFS($G$2:$G3; $G3;$J$2:$J3; $J3) - in O3[/TD]
[/TR]
[TR]
[TD] =COUNTIFS($G$2:$G4; $G4;$J$2:$J4; $J4) - in O4[/TD]
[/TR]
</tbody>[/TABLE]
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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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
 
Upvote 0
Re: SOLVED Please help for macro repair

Thank you so much.
I wish all the best.
 
Upvote 0
Re: SOLVED Please help for macro repair

You are welcome.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top