Need macro to Count Number of Dots Before the Word Starts

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Hello guys, In I column some of the cells starts with "." It might be start with two to six dots also i.e ".." to "......". After that word will start. Now i want to count number of dots before the word starts and add the count with value 1 the result should be reflect in corresponding cell in E column. see the example table below. Some times there will be space between the dots(". . . . ") my values starts from cell I2
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]E
[/TD]
[TD]I
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Adam
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]..Smith
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]. . David
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]...John
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]. . . .Rob
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Rick
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Matt
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD].Justin
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]. Miller
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi, assuming, as per the sample data, the dots only appear at the start - you could try this formula:

=IF(ISNUMBER(FIND(".",I2)),1+LEN(I2)-LEN(SUBSTITUTE(I2,".","")),"")

If you really did need code you could use the formula in VBA like this.

Code:
With Range("E2:E" & Range("I" & Rows.Count).End(xlUp).Row)
  .FormulaR1C1 = "=IF(ISNUMBER(FIND(""."",RC[4])),1+LEN(RC[4])-LEN(SUBSTITUTE(RC[4],""."","""")),"""")"
  .Value = .Value
End With
 
Upvote 0
Hello Form, the code is working fine. But i want to count the dots before the 1st word only not all the dots in the cell.
 
Upvote 0
It might be start with two to six dots

You could try this formula:

=IF(LEFT(I3)=".",MATCH(TRUE,INDEX(MID(SUBSTITUTE(I3," ",""),{1,2,3,4,5,6,7},1)<>".",0),0),"")

Or in code:

Code:
With Range("E2:E" & Range("I" & Rows.Count).End(xlUp).Row)
  .FormulaR1C1 = "=IF(LEFT(RC[4])=""."",MATCH(TRUE,INDEX(MID(SUBSTITUTE(RC[4],"" "",""""),{1,2,3,4,5,6,7},1)<>""."",0),0),"""")"
  .Value = .Value
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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