Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Macro to give different outputs dependent on result

Hi,

From what I've been learning I would have thought this was a simple Macro to
write. However I'm having a lot of trouble!!

Basically I want A macro that will check the value in cell A1 and if the
value equals 1 then it should give one output. but if it equals 2 it should
give another output etc for 4 or five outputs. I'm guessing that I need to
use the IF, then, else statement but can't seem to figure it out.

If someone could show me the code which does exactly this

If A1 = 1 then copy cell C1 and paste into D1 but if A1 = 2 then copy cell
C2 and paste into D2 but if A1 = 3 then copy cell C3 and paste into D4.

Then I can work from there with what I want it too do.

Thanks for your help!
Carl


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macro to give different outputs dependent on result

Sub carlos()
Dim v As Integer
v = Range("A1").Value
Range("C" & v).Copy Range("D" & v)
End Sub
--
Gary''s Student - gsnu200767
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Macro to give different outputs dependent on result

Hi
Two ways to do this - using Select Case and If..then

Select Case:

Select Case Range("A1").Value
Case 1: Range("D1").Value = Range("C1").Value
Case 2: Range("D2").Value = Range("C2").Value
Case 3: Range("D3").Value = Range("C3").Value
Case Else: 'whatever
End Select

If..then...else

With Range("A1")
If .Value = 1 then
Range("D1").Value = Range("C1").Value
elseIf .Value = 2 then
Range("D2").Value = Range("C2").Value
elseIf .Value = 3 then
Range("D3").Value = Range("C3").Value
else
'whatever
End If
End With

regards
Paul

On Feb 6, 10:22*am, Carlos wrote:
Hi, *

From what I've been learning I would have thought this was a simple Macro to
write. However I'm having a lot of trouble!!

Basically I want A macro that will check the value in cell A1 and if the
value equals 1 then it should give one output. but if it equals 2 it should
give another output etc for 4 or five outputs. I'm guessing that I need to
use the IF, then, else statement but can't seem to figure it out.

If someone could show me the code which does exactly this

If A1 = 1 then copy cell C1 and paste into D1 *but if A1 = 2 then copy cell
C2 and paste into D2 but if A1 = 3 then copy cell C3 and paste into D4.

Then I can work from there with what I want it too do.

Thanks for your help!
Carl


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Macro to give different outputs dependent on result

Cheers Paul.

That is brilliant. i've used the if one and it worked first time.. I just
couldn't get the code right.

Thanks for both of your help!

Carl

" wrote:

Hi
Two ways to do this - using Select Case and If..then

Select Case:

Select Case Range("A1").Value
Case 1: Range("D1").Value = Range("C1").Value
Case 2: Range("D2").Value = Range("C2").Value
Case 3: Range("D3").Value = Range("C3").Value
Case Else: 'whatever
End Select

If..then...else

With Range("A1")
If .Value = 1 then
Range("D1").Value = Range("C1").Value
elseIf .Value = 2 then
Range("D2").Value = Range("C2").Value
elseIf .Value = 3 then
Range("D3").Value = Range("C3").Value
else
'whatever
End If
End With

regards
Paul

On Feb 6, 10:22 am, Carlos wrote:
Hi,

From what I've been learning I would have thought this was a simple Macro to
write. However I'm having a lot of trouble!!

Basically I want A macro that will check the value in cell A1 and if the
value equals 1 then it should give one output. but if it equals 2 it should
give another output etc for 4 or five outputs. I'm guessing that I need to
use the IF, then, else statement but can't seem to figure it out.

If someone could show me the code which does exactly this

If A1 = 1 then copy cell C1 and paste into D1 but if A1 = 2 then copy cell
C2 and paste into D2 but if A1 = 3 then copy cell C3 and paste into D4.

Then I can work from there with what I want it too do.

Thanks for your help!
Carl



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro or formula to compare columns and give a result of the odd o Rhett C[_2_] Excel Discussion (Misc queries) 2 December 24th 09 02:26 AM
v-Lookup between values and give result -Help Yossy Excel Worksheet Functions 4 January 15th 09 05:43 PM
vlookup does not give the result in the cell even though it is kbee Excel Worksheet Functions 2 February 15th 08 08:45 AM
Getting a Result in vlookup dependent on another formula jhyatt Excel Worksheet Functions 1 August 27th 07 06:46 PM
Formula help. Different result dependent on answer martinco Excel Worksheet Functions 3 April 16th 05 04:40 PM


All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"