Forum

Notifications
Clear all

count consecutive blank cells

19 Posts
4 Users
0 Reactions
502 Views
(@rhysand)
Posts: 80
Trusted Member
 

Hello,

if you want VBA version:

put the following in a standard module

 

Public Sub Count_consecutive_empty_cells_in_row_2()

Dim sht As Worksheet
Dim LastRow As Long
Dim i As Integer, nCount As Integer
Dim rRange As Range, rng As Range
Dim storeC As Integer

Set sht = Application.ThisWorkbook.Worksheets("Distance")
sht.Activate

LastRow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row

For i = 2 To LastRow
     If Not rRange Is Nothing Then Set rRange = Nothing
     nCount = 0
     Set rRange = sht.Range("E" & i & ":" & "AD" & i)
     For Each rng In rRange
         If rng.Value = "" Then
             nCount = nCount + 1
             Debug.Print nCount
             If nCount >= 3 Then storeC = storeC + 1: nCount = 0
         Else
             nCount = 0
         End If
     Next rng
     sht.Range("A" & i).Value = storeC
     storeC = 0
Next i

If Not rRange Is Nothing Then Set rRange = Nothing
If Not sht Is Nothing Then Set sht = Nothing

End Sub

 

on the excel sheet with a command button

Option Explicit

Private Sub CommandButton2_Click()
     Call Count_consecutive_empty_cells_in_row_2
End Sub

 

capture.JPG

 
Posted : 01/12/2020 8:04 am
(@ateep23)
Posts: 9
Active Member
Topic starter
 

Hi Miguel,

i have tried your suggestion VBA coding, in one of my orginial sheet but nothing appearing.

Regards, Atif

 
Posted : 03/12/2020 1:17 am
(@rhysand)
Posts: 80
Trusted Member
 

Hello,

attached sample file

your excel file needs to be saved with permissions for macros, that is, with the extension (.xlsm)


confirm that these references are active in your VBE project:

img1-1.JPG

 

review what you’re doing wrong when trying to replicate my macro, because everything works

 

Miguel,

 
Posted : 03/12/2020 6:09 am
(@ateep23)
Posts: 9
Active Member
Topic starter
 

thank you everyone for your great support

 
Posted : 05/12/2020 1:43 am
Page 2 / 2
Share: