Including LastRow within a formula

SimonGeoghegan

New Member
Joined
Nov 5, 2013
Messages
39
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,523
Office Version
365
Platform
Windows
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,523
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,078,442
Messages
5,340,305
Members
399,366
Latest member
ahmed elsaid

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top