Including LastRow within a formula

SimonGeoghegan

Board Regular
Joined
Nov 5, 2013
Messages
68
Hi All,

I have some code which creates a "score" line within my spreadsheet. I need this formula to change each time I run my macro, as the number of questions it relates to is variable.

I have the formula:

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Range("B" & LastRow + 3).Value = "=SUM(COUNTIF(B$8:B$30,""Yes"")/SUM(COUNTA($A$8:$A$30)-COUNTIF(B$8:B$30,""N/A"")))"[/FONT]

Essentially, the "B$30","$A$30" both need replacing to the value of the last row instead of being a fixed value.

Can anyone advise how I'd go about this? I know that my code is just placing a pre-determined text at the minute so expecting I'll need to re-do the entire formula in a different way rather than simply replacing the above references.

Regards,
Simon
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
How about
Code:
Range("B" & LastRow + 3).Value = "=SUM(COUNTIF(B$8:B$" & LastRow & ",""Yes"")/SUM(COUNTA($A$8:$A$" & LastRow & ")-COUNTIF(B$8:B$" & LastRow & ",""N/A"")))"
or
Code:
Range("B" & LastRow + 3).FormulaR1C1 = "=SUM(COUNTIF(r8c2:r[-3]c2,""Yes"")/SUM(COUNTA(r8c1:r[-3]c1)-COUNTIF(r8c2:r[-3]c2,""N/A"")))"
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,744
Messages
6,174,252
Members
452,553
Latest member
red83

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