Home |
Search |
Today's Posts |
#1
|
|||
|
|||
if with macro
Hi,
The statement: "ElseIf Worksheets("main").Range ("B5").Value = 1 Then . " in the code below is not correct. If Worksheets("main").Range("B5").Value = 1 Then Sheets("Sheet1").Select Range("A1").Select Selection.Copy Sheets("sum").Select Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ElseIf Worksheets("main").Range("C5").Value = 1 Then Sheets("Sheet2").Select Range("A1").Select Selection.Copy Sheets("sum").Select Range("B1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("main").Select End If If only the value in sheet "main" cell B5 =1 OR only the value in sheet "main" C5=1 the code works fine BUT if both values B5=1 AND C5=1 then it works only for the first part of the if statement. Is there anybody who can help me to fix this error? |
#2
|
|||
|
|||
Simply turen this into two seperate if statements - where
you currently have your elseif put an endif and then a new if. -----Original Message----- Hi, The statement: "ElseIf Worksheets("main").Range ("B5").Value = 1 Then . " in the code below is not correct. If Worksheets("main").Range("B5").Value = 1 Then Sheets("Sheet1").Select Range("A1").Select Selection.Copy Sheets("sum").Select Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ElseIf Worksheets("main").Range("C5").Value = 1 Then Sheets("Sheet2").Select Range("A1").Select Selection.Copy Sheets("sum").Select Range("B1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("main").Select End If If only the value in sheet "main" cell B5 =1 OR only the value in sheet "main" C5=1 the code works fine BUT if both values B5=1 AND C5=1 then it works only for the first part of the if statement. Is there anybody who can help me to fix this error? . |
#3
|
|||
|
|||
If Worksheets("main").Range("B5").Value = 1 Then
Sheets("Sheet1").Select Range("A1").Copy Sheets("sum").Select Range("A1").PasteSpecial Paste:=xlPasteValues, _ Operation:=xlNone, SkipBlanks:=False, _ Transpose:=False End If If Worksheets("main").Range("C5").Value = 1 Then Sheets("Sheet2").Select Range("A1").Copy Sheets("sum").Select Range("B1").PasteSpecial Paste:=xlPasteValues, _ Operation:=xlNone, SkipBlanks:=False, _ Transpose:=False Sheets("main").Select End If -- HTH RP (remove nothere from the email address if mailing direct) "Tim" wrote in message ... Hi, The statement: "ElseIf Worksheets("main").Range ("B5").Value = 1 Then . " in the code below is not correct. If Worksheets("main").Range("B5").Value = 1 Then Sheets("Sheet1").Select Range("A1").Select Selection.Copy Sheets("sum").Select Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ElseIf Worksheets("main").Range("C5").Value = 1 Then Sheets("Sheet2").Select Range("A1").Select Selection.Copy Sheets("sum").Select Range("B1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("main").Select End If If only the value in sheet "main" cell B5 =1 OR only the value in sheet "main" C5=1 the code works fine BUT if both values B5=1 AND C5=1 then it works only for the first part of the if statement. Is there anybody who can help me to fix this error? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
excel macro inconsistency | Excel Discussion (Misc queries) | |||
Macro and If Statement | Excel Discussion (Misc queries) | |||
assign a macro to a control button | Excel Discussion (Misc queries) | |||
Macro help | Excel Discussion (Misc queries) | |||
macro interruption: help!!! | Excel Discussion (Misc queries) |