if with macro

T

Tim

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?
 
B

Ben McBen

Simply turen this into two seperate if statements - where
you currently have your elseif put an endif and then a new
if.
 
B

Bob Phillips

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top