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? |
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? . |
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? |
All times are GMT +1. The time now is 06:51 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com