VBA count nonblank cells in column of data.

maxf24

New Member
Joined
Mar 12, 2014
Messages
25
Hi, I would like a macro to count the number of blank cells in column B divide that by three and place the result as #Meters 3 cells down from last cell with data.


Example: (also the column could have more or less data with more or less blanks.

ABC
XYZ
XYZ
XYZ
XYZ
Blank
Blank
XYZ
XYZ
XYZ
Blank
Blank
XYZ
XYZ
XYZ
XYZ
XYZ
XYZ
XYZ
Blank
Blank
XYZ
XYZ
XYZ
XYZ
Blank
Blank
4 Meters

<tbody>
</tbody>
*The Formula for the Cell with # Meters I want it to use blank rows as the qualifier, but because there is a constant of 2 blanks I would like the divide the total of blanks by 2 to return the proper # of Meters. Each string of continuous data represents 1 meter.

This is the Macro I have tried to alter and use from a previous example, but have not had any luck with my limited skill.

Sub NumberofMeters()
Dim r As Range, rAbove As Range
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
Set r = ActiveCell
ActiveCell = Range("B:B").End(xlUp).Offset(2, 0)
Set rAbove = ActiveSheet.Range("B2:" & ActiveSheet.Range("b65536"). _
End(xlUp).Offset(2,0).Address).Select
r.Value = wf.CountBlank(rAbove) / 2
End Sub

Any help would be greatly appreciated!
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
Sub NumberofMeters()
Dim r As Range, rAbove As Range
Dim wf As WorksheetFunction
Dim Sh1 As Worksheet


Set wf = Application.WorksheetFunction
Set Sh1 = ActiveSheet
Set r = Sh1.Cells(Rows.Count, 2).End(xlUp).Offset(3)
Set rAbove = Sh1.Range("B2", r.Offset(-1))
r.Value = wf.CountBlank(rAbove) / 2
End Sub
 
Upvote 0
Brian, it actually did work the first time, it just inserted the solution on a different worksheet(because of my original coding). With a little tweaking it works great! Thanks for your help.

Here is the updated macro:
Sub NumberofMeters()Set wf = Application.WorksheetFunction
Set r = Cells(Rows.Count, 2).End(xlUp).Offset(3)
Set rAbove = Range("B2", r.Offset(-1))
r.Value = wf.CountBlank(rAbove) / 2
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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