Column Contents

Sal1

New Member
Joined
Apr 15, 2009
Messages
34
I would like to create a macro that does the following. Due to the fact that I can’t record these types of steps, I was wondering if I could get some help.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
Every time a cell in Column D contains NEW1 or OLD1, I would like “Customer” to be entered into Column G in the same row.
<o:p> </o:p>
Every time a cell in Column D contains OLD2, I would like “Assets” to be entered into Column G in the same row.
<o:p> </o:p>
Every time a cell in Column D contains NEW2, I would like Column G in the same row to contain “ShortTerm”
<o:p> </o:p>
Every time a cell in Column D contains OLD3, I would like Column G in the same row to contain “LongTerm”
 

Some videos you may like

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,)

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Hello and welcome to MrExcel.

Right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim s As String
If Target.Column = 4 Then
    Select Case (UCase(Target.Value))
        Case "NEW1", "OLD1": s = "Customer"
        Case "OLD2": s = "Assets"
        Case "NEW2": s = "Short Term"
        Case "OLD3": s = "Long Term"
    End Select
    If s <> "" Then Target.Offset(, 3).Value = s
End If
End Sub
 

Sal1

New Member
Joined
Apr 15, 2009
Messages
34
Thank you. I appreciate very much your help. Perhaps it’s my error but the code keeps asking for this part “If Target.Column = 4 Then” of the code to be debugged. Any thoughts?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
The code works for me. Did you copy it exactly?
 

Sal1

New Member
Joined
Apr 15, 2009
Messages
34

ADVERTISEMENT

I changed this line0 “Private Sub Worksheet_Change(ByVal Target As Range)”, otherwise I was not able to see it and run it when I pressed (Alt F8)
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Please change it back to the exact code that I posted. Then go back to your sheet and enter one of your values in column D. Column G will populate automatically.
 

Sal1

New Member
Joined
Apr 15, 2009
Messages
34
You are right. You are right. My mistake. I am sorry. Thank you very much for your help! This works very well.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,610
Members
414,080
Latest member
penguin23

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
Top