VBA help on row count in if/then statement

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
886
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - my current vba will evaluate if column H is > 2 if it is then it proceeds if not then it will stop. For some reason if i select the cell H (myself) the count is 2
1680021932834.png
but my VBA is evaluating something greater than 2. Am i using the wrong code for this?

VBA Code:
If WsDIST.Range("H" & rows.count).End(xlUp).row > 2 Then

1680022019224.png
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Not sure what you're asking. That returns the row number of the last value in column H, which would just happen to be the row count if you include all rows (even blank cells in H).
 
Upvote 0
Okay that may explain it - I am looking for something to count the used data in column H which in my case is really 2.
 
Upvote 0
So this should be 2 and not 9?
1680029959021.png

Then you just need to count non blank cells?
 
Upvote 0
Yea well technically 3. but yes 2 would be preferred to ignore the header. via VBA would be desired.
Take a look at the link I provided. Fairly simple to get the count using COUNTA, even in VBA.
 
Upvote 0
Yea well technically 3
Technically 2 for what I posted. There is no header in what I showed; that is a column label.
I was going to say use CountA if I was on the right track but too late I guess. However, you will still need to find the last row with a value in H and then set the range accordingly to eliminate header row(s).
 
Upvote 0
However, you will still need to find the last row with a value in H and then set the range accordingly to eliminate header row(s).
Or take the lazy way out and just use COUNTA on the whole column, and then subtract 1 for the header!
;)
 
Upvote 0

Forum statistics

Threads
1,225,225
Messages
6,183,686
Members
453,180
Latest member
Systemize

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