macro to put differnet values into a cell depending on the othere cell

tonylpcs@yahoo.co.uk

Active Member
Joined
Dec 19, 2007
Messages
379
Hi Everyone,

I need a macro that i can use to input a value into a cell depending on what the other cells value is:

when i run it i need it to say:

if cell A1 = "2" then input cell F5 with "hello" however if cell A1 = "yes" then enter in cell F5 "goodbye" but if cell A1 = "wet" then enter in cell F5 "sold by tony"

can anyone give me the code for this please?

thanks

Tony
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this untested:
Code:
Public Sub tonyswish()
Select Case Range("A1").Value
Case 2
Range("F5").Value = "hello"
Case "yes"
Range("F5").Value = "goodbye"
Case "wet"
Range("F5").Value = "sold by tony"
Case Else
Range("F5").Value = "Not defined by tony!"
End Select
End Sub
 
Upvote 0
On Second thoughts, you can create a lookup table in Excel which will prove to be dynamic and flexible like:
Excel Workbook
ABCDEF
12INPUTRESPONSE
22hello
3yesgoodbye
4wetsold by tony
5hello
Sheet1
If you have Excel 2007 & above you can use this formula:

<TABLE style="BORDER-BOTTOM-STYLE: groove; BORDER-BOTTOM-COLOR: #00ff00; BORDER-RIGHT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-TOP-STYLE: groove; COLOR: #000000; BORDER-RIGHT-COLOR: #00ff00; FONT-SIZE: 10pt; BORDER-LEFT-STYLE: groove; BORDER-LEFT-COLOR: #00ff00"><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-FAMILY: Arial; FONT-SIZE: 9pt" border=1 cellSpacing=0 cellPadding=2><TR style="BACKGROUND-COLOR: #cacaca; FONT-SIZE: 10pt"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>F5</TD><TD>=IFERROR(VLOOKUP(A1,B2:C4,2,0),"not defined by tony!")</TD></TR></TABLE></TD></TR></TABLE>



In Excel 2003 and below:
<TABLE style="BORDER-BOTTOM-STYLE: groove; BORDER-BOTTOM-COLOR: #00ff00; BORDER-RIGHT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-TOP-STYLE: groove; COLOR: #000000; BORDER-RIGHT-COLOR: #00ff00; FONT-SIZE: 10pt; BORDER-LEFT-STYLE: groove; BORDER-LEFT-COLOR: #00ff00"><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-FAMILY: Arial; FONT-SIZE: 9pt" border=1 cellSpacing=0 cellPadding=2><TR style="BACKGROUND-COLOR: #cacaca; FONT-SIZE: 10pt"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>F5</TD><TD>=IF(ISERROR(VLOOKUP(A1,B2:C4,2,0)),"not defined by tony!",VLOOKUP(A1,B2:C4,2,0))</TD></TR></TABLE></TD></TR></TABLE>

 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,628
Members
452,933
Latest member
patv

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