Hi All,
I have an data in a columns. Here I need to count the non-blanks and blank records. Please find the attachment file.
Hi All,
I have an data in a columns. Here I need to count the non-blanks and blank records. Please find the attachment file.
Try:
Assumes you'll have more than two characters. Note: the blank cells in your sample contains spaces.![]()
Sub sathishkmaazzbb() Dim x As Long Dim y As Long Dim i As Long x = 0 y = 0 For i = 2 To Range("A" & Rows.count).End(3)(1).Row If Len(Range("A" & i)) < 2 Then x = 0 Range("B" & i).Value = x ElseIf Len(Range("A" & i)) >= 2 Then x = x + 1 Range("B" & i).Value = x End If Next i End Sub
Is it possible to modify the code to get the results like attachment.
Is it possible to modify the code to get the counts like attachment.
Hello sathishkm,
You really don't need a VBA macro for this. It can be done easily with Formulas.
Call B2 Formula: =IF(OR(A2=" ", A2=""), 0,1)
Cell B3 Formula: =IF(OR(A3= " ", A3 =""),0, B2+1)
Note: Cell B3 formula can be dragged down as far as needed in the column.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Modified:
![]()
Sub sathishkmaazzbb() Dim x As Long Dim y As Range Dim i As Long x = 0 For i = 2 To Range("A" & Rows.count).End(3)(1).Row If Len(Range("A" & i)) < 2 Then x = 0 Range("B" & i).Value = x Range("C" & i - 1).Value = Range("B" & i - 1).Value ElseIf Len(Range("A" & i)) >= 2 Then x = x + 1 Range("B" & i).Value = x End If Next i Range("C2:C" & Range("B" & Rows.count).End(3)(1).Row).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[+1]C" For Each y In Range("C2:C" & Range("B" & Rows.count).End(3)(1).Row) If y.offset(, -1) <> 0 Then y.offset(, -1) = y End If Next y Range("C2:C" & Range("B" & Rows.count).End(3)(1).Row).ClearContents End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks