Incremental value with a text prefix and a suffix

Rowane

New Member
Joined
Sep 25, 2015
Messages
15
Would appreciate if someone out there could help...I am using the following code to increase my PO number.
My output should look like this - PO09-001/15 where PO09 is fixed and /15 is fixed. However when i run the macro, it turns out PO09-2/15 instead of PO09-002/15. Please help me correct the code. Thank you very much.


Dim i As Integer


Range("C5").Value = "PO09-" & Val(Mid(Range("C5"), 6, Len(Range("C5")) - 5)) + 1 & "/15"
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi.
As an alternative suggestion why not use a helper cell which would negate need to manipulate cell value in code?

formula in cell C5

="PO09-"&TEXT(C1,"000")&"/15"

in this example I have selected C1 where you would increment PO numbers but it can be any cell.

Hope Helpful

Dave
 
Upvote 0
Hi Dave

Thanks for offering help. Pls pardon me as I am really alien to VBA. My increment PO is on Cell C5. When you suggested the formula, do I add on to the line to the code or?


Hi.
As an alternative suggestion why not use a helper cell which would negate need to manipulate cell value in code?

formula in cell C5

="PO09-"&TEXT(C1,"000")&"/15"

in this example I have selected C1 where you would increment PO numbers but it can be any cell.

Hope Helpful

Dave
 
Upvote 0
Hi Rowane.....
Try this
Code:
Range("C5").Value = "PO09-" & Format(Val(Mid(Range("C5"), 6, Len(Range("C5")) - 5)) + 1, "000") & "/15"
 
Upvote 0
Hi Dave

Thanks for offering help. Pls pardon me as I am really alien to VBA. My increment PO is on Cell C5. When you suggested the formula, do I add on to the line to the code or?

You place the Formula in C5 & just increment numeric value in your chosen helper cell. No VBA manipulation required.

Dave
 
Upvote 0
Would appreciate if someone out there could help...I am using the following code to increase my PO number.

Range("C5").Value = "PO09-" & Val(Mid(Range("C5"), 6, Len(Range("C5")) - 5)) + 1 & "/15"
Try that code line like this...

Range("C5").Value = "PO09-" & Format(Mid(Range("C5").Value, 6, 3) + 1, "000") & "/15"
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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