Converting string

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
539
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have string values representing the month of a transaction in two digit format. I need the values in MMM format and am currently using a case statement to convert them. I wanted to know if there was a way to use the format function to accomplish the same thing with one line of code. I've tried the line below but it always returns JAN no matter which two digit string is present.

Code:
newMonth = UCase(Format(oldMonth, "MMM"))

I want to go from this:
01
02
03

to this:
JAN
FEB
MAR
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Not sure about the VBA for this conversion, but can you just do it in Excel with a quick VLOOKUP? You can easily make a table with the MM and MMM equivalents and then just lookup your value in the table and return the second column. Then paste the values into your original column and delete the vlookup column.
 
Upvote 0
Unfortunately this runs as part of a scripted batch job so I need to do it in VBA. I have something that works, I just wanted to know if it was possible to replace the case statement with a shorter piece of code.

Thanks
 
Upvote 0
Perhaps this?

Code:
newMonth = UCase(Format(DateSerial(Year(Date), CInt(oldMonth), 1), "MMM"))
 
Upvote 0
I knew I needed to convert it but couldn't figure out which function. This works great.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

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