Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default If then else

I need help with an if then else macro

If Sheets("data Worksheet").Range("H26") 0 Then Range("H26").Select Else
Range("BA1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Test Database").Select
Range("F9").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

What I am looking for is to have H26 on the data worksheet displayed on the
Test database worksheet. But with this macro the H26 cell on the test
database worksheet is being copied on to the same sheet but in a different
place. Why?

Can anyone help?

Eric
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default If then else

The why is because you don't qualify the "Range("H26")" after "Then"
with the name of the sheet, so

Range("H26").Select

is equivalent to

ActiveSheet.Range("H26").Select

However, you could avoid this problem (and be far more efficient) if you
didn't rely on Selections at all:


With Sheets("data Worksheet").Range("H26")
If .Value 0 Then _
Sheets("Test Database").Range("F9").Value = .Value
End With

Note the "." before .Value which indicates that the property belongs to
the object in the With statement (i.e., Sheets("data
Worksheet").Range("H9")).


In article ,
Eric wrote:

I need help with an if then else macro

If Sheets("data Worksheet").Range("H26") 0 Then Range("H26").Select Else
Range("BA1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Test Database").Select
Range("F9").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

What I am looking for is to have H26 on the data worksheet displayed on the
Test database worksheet. But with this macro the H26 cell on the test
database worksheet is being copied on to the same sheet but in a different
place. Why?

Can anyone help?

Eric

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default If then else

JE said:

Note the "." before .Value which indicates that the property belongs to
the object in the With statement (i.e., Sheets("data
Worksheet").Range("H9")).

But I think he meant:

Note the "." before .Value which indicates that the property belongs to
the object in the With statement (i.e., Sheets("data
Worksheet").Range("H26")).





"JE McGimpsey" wrote:

The why is because you don't qualify the "Range("H26")" after "Then"
with the name of the sheet, so

Range("H26").Select

is equivalent to

ActiveSheet.Range("H26").Select

However, you could avoid this problem (and be far more efficient) if you
didn't rely on Selections at all:


With Sheets("data Worksheet").Range("H26")
If .Value 0 Then _
Sheets("Test Database").Range("F9").Value = .Value
End With

Note the "." before .Value which indicates that the property belongs to
the object in the With statement (i.e., Sheets("data
Worksheet").Range("H9")).


In article ,
Eric wrote:

I need help with an if then else macro

If Sheets("data Worksheet").Range("H26") 0 Then Range("H26").Select Else
Range("BA1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Test Database").Select
Range("F9").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

What I am looking for is to have H26 on the data worksheet displayed on the
Test database worksheet. But with this macro the H26 cell on the test
database worksheet is being copied on to the same sheet but in a different
place. Why?

Can anyone help?

Eric


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



All times are GMT +1. The time now is 11:20 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"