Macro question..

Will17

New Member
Joined
Apr 27, 2011
Messages
5
Just wanting to know if this is possible. I have a list of plan numbers that I need to add a PS, PS0, PS00, or PS000 depending on how many digits (ex: PS plus 6 digits, ie PS000111). What I usually do is just sort the plan numbers, insert a new column a and c, add PS, PS0, etc depending on what is needed, and concatenate in column c, then paste special values and delete columns a and b. Each week the data is different, different amount of rows, different number of plans that need the PS, PS0, etc.. so can a macro see the difference and automatically add the PS000 to the 111, PS00 for plan number 1111, etc in Column C?

Hopefully I'm making this clear.. I realize it's kinda wordy.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
you could use the following code. Highlight the values to updated and run the add_ps macro...

Code:
Public Sub add_ps()

For Each c In Selection
    c.Value = "PS" & Format(c.Value, "000000")
Next c

End Sub

You could also use a formula

="PS" & TEXT(A1,"000000")
 
Upvote 0
Or...
  • Select the column with the numbers.
  • Right-click on the selected column and select Format Cells
    • On the Number tab, select...
    • Catagory: Custom
    • Type:"PS"000000
    • OK
 
Upvote 0
Thanks so much. That's a heck of a lot simpler than I thought it would be. Don't know why I never thought of the "PS"00000. Gave it a quick test and it (obviously) worked.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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