Need macro code please to add a word to beginning of a cell

Henner

Board Regular
Joined
May 16, 2002
Messages
174
Hi,

It would be appreciated if someone could provide me with macro code to add the word DEC at the beginning of every cell in Column C, but only when the 3rd character in a cell in Column A is a letter of the alphabet.

For example:

Column A Column B Column C
06N0104 This is a test

BECOMES

Column A Column B Column C
06N0104 DEC This is a test


Thanks
Paul
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Re: Need macro code please to add a word to beginning of a c

Henner said:
Hi,

It would be appreciated if someone could provide me with macro code to add the word DEC at the beginning of every cell in Column C, but only when the 3rd character in a cell in Column A is a letter of the alphabet.

For example:

Column A Column B Column C
06N0104 This is a test

BECOMES

Column A Column B Column C
06N0104 DEC This is a test

Thanks
Paul

You could enter a formula in Col C like this

DEC This is a Test =IF(ISTEXT(MID(A6,3,1)),"DEC This is a Test","")
 
Upvote 0
Re: Need macro code please to add a word to beginning of a c

Well, this works but I'm not sure the For-Next/Select Case is the best structure --

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> AddDEC()
<SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, LastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
<SPAN style="color:#00007F">With</SPAN> ActiveSheet
    LastRow = .[a65536].End(3).Row
    <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> LastRow
        <SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> Mid(.Cells(i, 1), 3, 1)
            <SPAN style="color:#00007F">Case</SPAN> "a" <SPAN style="color:#00007F">To</SPAN> "z", "A" <SPAN style="color:#00007F">To</SPAN> "Z"
                .Cells(i, 3) = "DEC " & .Cells(i, 3)
            <SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Else</SPAN>
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN>
    <SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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