counting rows and adding cells to the bottom of the list

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
Hi

Can anyone explain how you write VBA which counts the amount of rows in a cell range and then adds values to the bottom two cells of that cell range.

So far i have the code below but it doesn't seem to do anything, it doesn't add the values to the correct cells

Code:
k = WorksheetFunction.CountA(.Range("A2:A3000"))
h = k + 2
f = k + 3

wbGCT.Sheets("Graphing").Select: Range ("C" & h).Value = "National_Average_NoSample"

wbGCT.Sheets("Graphing").Select: Range("C" & f).Value = "UpperQuartile_TRUE_NoSample"

Does anyone know how to do this?

Thanks

Jessciaseymour
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try

Code:
With wbGCT.Sheets("Graphing")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("C" & LR + 2).Value = "National_Average_NoSample"
    .Range("C" & LR + 3).Value = "UpperQuartile_TRUE_NoSample"
End With
 
Upvote 0
Hi,

Not sure what you mean by 'adds values to the bottom two cells of that cell range.' but you can use this to display the last row of your data:

Range("A" & rows.count).end(xlup).row

The above will give you the row of the last cell that has data in, however if you want to find how many rows are populated then you could use this (assuming there is no data in row 1):

Code:
    topRow = Range("A1").End(xlDown).Row
    lRow = Range("A" & Rows.Count).End(xlUp).Row
    
    numberofRows = lRow - topRow
 
Upvote 0
Something like this...

Code:
Dim Last_Row As Long

With Sheets("Graphing")
Last_Row = .Range("C" & Rows.Count).End(xlUp).Row

.Cells(Last_Row+1,3) = "National_Average_NoSample"
.Cells(Last_Row+2,3) = "UpperQuartile_TRUE_NoSample"

End With
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,504
Members
452,917
Latest member
MrsMSalt

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