Insert Text based on match macro help PLEASE

norcman

New Member
Joined
Feb 4, 2004
Messages
7
Hello everybody.

I'm seeking some assistance with a macro I need for a daily report. I need the value of each cell in column A to be compared to a given set of values. If the cell value matches a certain predefined value a specified text value is placed in the corresponding cell in column B. Let me give an example if my description kinds of stinks.

Lets say these are my predefined values and corresponding text
1 dog
2 cat
3 rabbit
4 frop
5 snake

If cell A1 contains the value "3" I would like the text "rabbit" to be entered into cell B1. If cell A6 contains the value "5" I would like the text "snake" to be entered into B6. If cell A8 contains the value "1" I would like the text "dog" to be entered into cell B8. Since I have more than 3 conditions I can't use the conditional formatting option. I need the conditions to be applied to all cells in column A that contain a value.

Thanks for your help!!!! Y'all rock!!!

NORC
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

north19701

Active Member
Joined
Jun 17, 2003
Messages
491
Code:
Sub Macro1()
With Range("b1:b" & Range("a65536").End(xlUp))
.FormulaR1C1 = "=VLOOKUP(RC[-1],{1,""dog"";2,""cat"";3,""rabbit"";4,""frop"";5,""snake""},2,FALSE)"
.Copy
.PasteSpecial (xlPasteValues)
End With
Application.CutCopyMode = False
End Sub

would this help get you started?
 

norcman

New Member
Joined
Feb 4, 2004
Messages
7
Yeah, thanks I'll play with this for a while. I did notice when running the macro it doesn't check duplicate values. For instance if my cells in column A contained:

A1 1
A2 2
A3 1
A4 2

It only returns
A1 1 B1 dog
A2 2 B2 cat
A3 1 B3
A4 2 B4

It leaves cells b3 and b4 blank.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,951
Messages
5,856,477
Members
431,817
Latest member
db74

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