VBA: replace numbers in one column with text

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,368
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
For the sake of learning a new technique in VBA, the code below works fine to replace certain numbers with text, but can it be converted into an array construct where it uses Lbound and Ubound? Is there a better method?

Code:
[FONT=arial]Sub ReplaceNumbers()[/FONT]
[FONT=arial]    Dim c As Range[/FONT]
[FONT=arial]    For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))[/FONT]
[FONT=arial]        Select Case c.Value[/FONT]
[FONT=arial]        Case 1[/FONT]
[FONT=arial]            c.Value = "Working Project"[/FONT]
[FONT=arial]        Case 2[/FONT]
[FONT=arial]            c.Value = "Delayed Project"[/FONT]
[FONT=arial]        Case 3[/FONT]
[FONT=arial]            c.Value = "Completed Project"[/FONT]
[FONT=arial]        End Select[/FONT]
[FONT=arial]    Next c[/FONT]
[FONT=arial]End Sub[/FONT]
 
Thank you Peter.

Those comments are very valuable and will truly help in understanding the different codes and there unintended consequences.

Actually, I should say, possibly my lack of being able to articulate my requirements.
 
Last edited:
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Peter,

Thanks for your reply #10.
You are welcome. However, your response gave me reason to look back at that post and I was surprised by my own (red) timing values as I was sure that Evaluate over such a large range & done 3 times would not be that fast. I looked back at my original test results and realised that I misplaced the decimal point when writing the result of your code to my post. I have edited that post now to make the correction.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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