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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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