Thread: if with macro
View Single Post
  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default

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?