#1   Report Post  
Tim
 
Posts: n/a
Default 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   Report Post  
Ben McBen
 
Posts: n/a
Default

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



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
excel macro inconsistency JM Excel Discussion (Misc queries) 2 December 9th 04 01:13 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
assign a macro to a control button ewan72 Excel Discussion (Misc queries) 1 December 3rd 04 02:04 PM
Macro help Jeff Garrett Excel Discussion (Misc queries) 11 December 1st 04 08:47 PM
macro interruption: help!!! mario milani Excel Discussion (Misc queries) 1 November 30th 04 06:02 PM


All times are GMT +1. The time now is 12:59 PM.

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

About Us

"It's about Microsoft Excel"