Macro to expand initial number for given numbers

Fractalis

Active Member
Joined
Oct 11, 2011
Messages
310
Office Version
  1. 2019
Platform
  1. Windows
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.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
So basically you just want to be prompted for a number, and have vba append the word "selected" to the adjacent cell?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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