Before or after the “X” if there is any number count them.

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

Data range B23:AO36 each row has numbers and text “X”, I want before or after the “X” if there is any number keep count them 1, 2, 3, 4….and so on. And put the result in range B5:AO18 as shown in example sheet below.

Please suggest if possible a VBA solution.

NX.xls
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAO
1
2
3
4Serial Numbers12345678910111213141516171819202122232425262728293031323334353637383940
511X12X1234X123456789
6212345678910111213141516171819
731234XX12345678X1X12
8412345XX1234X123XX1X
9512345678X123XXXX123
1061234X1X12345X123456
117X12X123456XX12X1234
128X123456X123456789X1
139123456789X1X123456X
14101X12X1234XX12X123X1
1511X12XX123456789XX123
1612XX12XX123456X12XX12
1713X123X12X12XXX1X1X1X
18141X123X1XXX1XXX1X123
19
20
21
22Serial Numbers12345678910111213141516171819202122232425262728293031323334353637383940
2311X11X1111X111111121
2421111111121111111212
2531222XX21221122X1X22
26412111XX1111X121XX1X
27512112111X122XXXX111
2862111X1X11121X221121
297X11X121212XX21X2121
308X121211X212211112X1
319112111221X2X121211X
32102X12X2112XX11X222X2
3311X11XX222122111XX111
3412XX11XX111222X22XX11
3513X222X12X21XXX1X1X1X
36142X121X1XXX2XXX1X221
37
38
39
Hoja5


Thank you in advance

Regards,
Kishan
 
OK, try this instead.

VBA Code:
Sub Count_Numbers_v2()
  With Range("B5").Resize(14, Rows("23:36").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column - 1)
    .Value = .Offset(18).Value
    .SpecialCells(xlConstants, xlNumbers).FormulaR1C1 = "=N(RC[-1])*(COLUMN(RC)>2)+1"
    .Value = .Value
  End With
End Sub
Thank you, Peter sir. This one worked 100% perfect! With my actual layout (y)

Have a good start of the week and Good Luck.

My Best Regards
Kishan :)
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,215,165
Messages
6,123,391
Members
449,098
Latest member
ArturS75

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