Macro to expand initial number for given numbers

Fractalis

Active Member
Joined
Oct 11, 2011
Messages
252
I have a complex problem that I think only can be done with VBA, but I'm not idea how to do it. Maybe someone could help me.

I want to mark with "Selected" some given numbers that could be 1 or more. All begin with 5, but in order to mark the given numbers
the series that begin with 5 should be expanded.

For example, If I have only 3 numbers "to mark", these are 543, 5787, 59300, the output of numbers should consider all numbers
that begin with 5, adding "Selected" to those 3 given numbers.

The output would be:
Code:
50
51
52
53
540
541
542
543 "Selected"
544
545
546
547
548
549
55
56
570
571
572
573
574
575
576
577
5780
5781
5782
5783
5784
5785
5786
5787 "Selected"
5788
5789
579
58
59
58
590
591
592
59300 "Selected"
59301
59302
59303
59304
59305
59306
59307
59308
59309
5931
5932
5933
5934
5935
5936
5937
5938
5939
594
595
596
597
598
599
I hope make sense

Thanks for any help.
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

NeonRedSharpie

Well-known Member
Joined
Jul 14, 2014
Messages
1,678
So basically you just want to be prompted for a number, and have vba append the word "selected" to the adjacent cell?
 

Fractalis

Active Member
Joined
Oct 11, 2011
Messages
252
Hello NeonRedSharpie,

Actually what I would know is the given number or numbers (all of then have in common that begin with the same digit), in this
case the given numbers are three, 543, 5787 and 59300.

Then all 3 numbers begin with "5", so, in order to show "Selected" next to the given numbers, the number 5 should be
disaggregated/detailed to show the given numbers, but always considering all numbers that begin with 5.

Another simplest/shortest example would be:
Given numbers 52 and 58, then the output would be:
Code:
50
51
52 "Selected"
53
54
55
56
57
58 "Selected"
59

But if the given values are 523 and 58 the output would be:
Code:
50
51
520
521
522
523 "Selected"
524
525
526
527
528
529
53
54
55
56
57
58 "Selected"
59

This means that if the given number is 523, I need to expand 5 with 3 digits, and detailing the series 52X. I hope make sense my explanation.

Thanks again for any help
 

Watch MrExcel Video

Forum statistics

Threads
1,108,998
Messages
5,526,161
Members
409,685
Latest member
Bellybb

This Week's Hot Topics

Top