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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try

VBA Code:
Sub Count_Numbers()
  With Range("B5").Resize(14, Rows("23:36").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column - 1)
    Range("B23:B36").Resize(, .Columns.Count).Copy Destination:=.Cells(1, 1)
    .SpecialCells(xlConstants, xlNumbers).FormulaR1C1 = "=N(RC[-1])*(COLUMN(RC)>2)+1"
    .Value = .Value
  End With
End Sub
 
Upvote 1
Try

VBA Code:
Sub Count_Numbers()
  With Range("B5").Resize(14, Rows("23:36").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column - 1)
    Range("B23:B36").Resize(, .Columns.Count).Copy Destination:=.Cells(1, 1)
    .SpecialCells(xlConstants, xlNumbers).FormulaR1C1 = "=N(RC[-1])*(COLUMN(RC)>2)+1"
    .Value = .Value
  End With
End Sub
Hello Peter, I want conform that your macro has result as request perfectly ok.

Thank you for you kind help and time.

Have a good weekend, Good Luck!

Kind Regards,
Kishan :)
 
Upvote 0
You're welcome. Thanks for the confirmation. (y)
Hello Peter_SSs, I need your help again as I did not mention B5:AO18 cell have conditional format if it “X” highlight in blue with font white.

When I applied code with original data it erased the CF. Please can you help with this issue so it remain the CF. Sorry for the trouble.

Kind Regards,
Kishan
 
Upvote 0
B5:AO18 cell have conditional format if it “X” highlight in blue with font white.
Perhaps include that information with XL2BB in future?

1684064519941.png


How were the 'X' values formatted with blue background and white font in rows 23:36?
 
Upvote 1
Perhaps include that information with XL2BB in future?

View attachment 91599

How were the 'X' values formatted with blue background and white font in rows 23:36?
Hello, Peter, I did not new it thank you for letting me know I will follow-up in the feature. And also going to try now to check how it works.
CF...it is in the range B5:AW18

NX.xls
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAW
51X12X1234X123456789
612345678910111213141516171819
71234XX12345678X1X12
812345XX1234X123XX1X
912345678X123XXXX123
101234X1X12345X123456
11X12X123456XX12X1234
12X123456X123456789X1
13123456789X1X123456X
141X12X1234XX12X123X1
15X12XX123456789XX123
16XX12XX123456X12XX12
17X123X12X12XXX1X1X1X
181X123X1XXX1XXX1X123
Hoja5
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:AW18Cell Value="X"textYES


Kind Regards,
Kishan
 
Last edited:
Upvote 0
CF...it is in the range B5:AW18
Yes, you indicated before that there was CF in rows 5:18. My question was
How were the 'X' values formatted with blue background and white font in rows 23:36?
I was asking because in your image they are coloured blue with white font and my code copied that to rows 5:18 so I was wondering if you really needed that CF in rows 5:18?
 
Upvote 0
Yes, you indicated before that there was CF in rows 5:18. My question was

I was asking because in your image they are coloured blue with white font and my code copied that to rows 5:18 so I was wondering if you really needed that CF in rows 5:18?
Hello, Peter, Oh, I see that you are right. In my opening post I made X colour manually to show the example clearer.

I'm sorry anyone can get confused as it wasn't clarified in the question about it. Here is the actual layout. Please can you give me a VBA solution which can work on this original layout?

Data range is in cells B23:AW36 and I need the result in the range A5:AW18 in this range the “X” has CF as shown below.

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
Hoja5
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:AW18Cell Value="X"textYES


Kind Regards,
Kishan
 
Upvote 0
In my opening post I made X colour manually to show the example clearer.

.... Here is the actual layout.
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
 
Upvote 1
Solution

Forum statistics

Threads
1,215,172
Messages
6,123,438
Members
449,100
Latest member
sktz

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