Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Variable difficulties

Hi-
Can you tell me where I am wrong in regard to this code. Below I have noted
where it causes an error;



Sub MovePastTradesLoop()

'Define Variables
Dim TradesEnteredPast As Range, PastCheck As Range


With Sheets("Analysis")
Set TradesEnteredPast = Range("at17:at56")
End With


'Loop: Check for complete trades, copy to Trade History
For X = 1 To TradesEnteredPast.Count
Set PastCheck = TradesEnteredPast(X)



If PastCheck.Value = "True" Then

PastCheck.EntireRow.Select ERRORS OUT HERE
Selection.Copy
Sheets("TradeHistory").Select
Range("A4").Activate
Selection.End(xlDown).Select
ActiveCell.Offset(rowoffset:=1, columnoffset:=0).Activate
ActiveCell.EntireRow.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
Sheets("Analysis").Select
Range("A1").Select
Else
MsgBox ("OK") 'Goes with Else. Comment out
Exit Sub 'Goes with Else. Comment it out.
End If
Next 'Ends "For Each" Loop


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Variable difficulties


The first part of the problem lies in the following code.

With Sheets("Analysis")
Set TradesEnteredPast = Range("at17:at56")
End With


For the Range to be subordinate to the Sheets("Analysis") object in the With
statement, you *must* preceed the Range with a period. Without the period,
Range refers to a range on whatever sheet happens to be active, which is not
necessarily the "Analysis" sheet. With the period before Range, Range refers
to the sheet specified in the With statement. For example,

With Sheets("Analysis")
Set TradesEnteredPast = .Range("at17:at56") '<<< Note period before "Range"
End With

The next problem is with

PastCheck.EntireRow.Select

If the worksheet that contains the range referenced by PastCheck is not the
active worksheet, the Select method will fail. In order to Select a Range,
the worksheet containing that Range must be active. So, you could use

With PastCheck
.Worksheet.Select '<<< Note leading period before "Worksheet"
.Select ' <<< Note leading period before "Select"
End With


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)






"Andyjim" wrote in message
...
Hi-
Can you tell me where I am wrong in regard to this code. Below I have
noted
where it causes an error;



Sub MovePastTradesLoop()

'Define Variables
Dim TradesEnteredPast As Range, PastCheck As Range


With Sheets("Analysis")
Set TradesEnteredPast = Range("at17:at56")
End With


'Loop: Check for complete trades, copy to Trade History
For X = 1 To TradesEnteredPast.Count
Set PastCheck = TradesEnteredPast(X)



If PastCheck.Value = "True" Then

PastCheck.EntireRow.Select ERRORS OUT HERE
Selection.Copy
Sheets("TradeHistory").Select
Range("A4").Activate
Selection.End(xlDown).Select
ActiveCell.Offset(rowoffset:=1, columnoffset:=0).Activate
ActiveCell.EntireRow.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
Sheets("Analysis").Select
Range("A1").Select
Else
MsgBox ("OK") 'Goes with Else. Comment out
Exit Sub 'Goes with Else. Comment it out.
End If
Next 'Ends "For Each" Loop


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Variable difficulties

Thanks to you and Don and Rick....you guys saved the day!

"Chip Pearson" wrote:


The first part of the problem lies in the following code.

With Sheets("Analysis")
Set TradesEnteredPast = Range("at17:at56")
End With


For the Range to be subordinate to the Sheets("Analysis") object in the With
statement, you *must* preceed the Range with a period. Without the period,
Range refers to a range on whatever sheet happens to be active, which is not
necessarily the "Analysis" sheet. With the period before Range, Range refers
to the sheet specified in the With statement. For example,

With Sheets("Analysis")
Set TradesEnteredPast = .Range("at17:at56") '<<< Note period before "Range"
End With

The next problem is with

PastCheck.EntireRow.Select

If the worksheet that contains the range referenced by PastCheck is not the
active worksheet, the Select method will fail. In order to Select a Range,
the worksheet containing that Range must be active. So, you could use

With PastCheck
.Worksheet.Select '<<< Note leading period before "Worksheet"
.Select ' <<< Note leading period before "Select"
End With


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)






"Andyjim" wrote in message
...
Hi-
Can you tell me where I am wrong in regard to this code. Below I have
noted
where it causes an error;



Sub MovePastTradesLoop()

'Define Variables
Dim TradesEnteredPast As Range, PastCheck As Range


With Sheets("Analysis")
Set TradesEnteredPast = Range("at17:at56")
End With


'Loop: Check for complete trades, copy to Trade History
For X = 1 To TradesEnteredPast.Count
Set PastCheck = TradesEnteredPast(X)



If PastCheck.Value = "True" Then

PastCheck.EntireRow.Select ERRORS OUT HERE
Selection.Copy
Sheets("TradeHistory").Select
Range("A4").Activate
Selection.End(xlDown).Select
ActiveCell.Offset(rowoffset:=1, columnoffset:=0).Activate
ActiveCell.EntireRow.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
Sheets("Analysis").Select
Range("A1").Select
Else
MsgBox ("OK") 'Goes with Else. Comment out
Exit Sub 'Goes with Else. Comment it out.
End If
Next 'Ends "For Each" Loop


End Sub


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
Continuing Difficulties W/ Sum For Variable-length Column Chuckles123[_8_] Excel Programming 2 October 5th 04 05:43 AM
Continuing Difficulties W/ Sum For Variable-length Column Chuckles123[_13_] Excel Programming 0 October 5th 04 04:31 AM
Continuing Difficulties W/ Sum For Variable-length Column Chuckles123[_11_] Excel Programming 1 October 5th 04 03:28 AM
Continuing Difficulties W/ Sum For Variable-length Column Chuckles123[_3_] Excel Programming 3 October 4th 04 12:01 AM
Continuing Difficulties W/ Sum For Variable-length Column Chuckles123[_7_] Excel Programming 0 October 3rd 04 09:58 PM


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