LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default variable doesn't reference correct column

I am stumped. The subroutine below runs fine, but when I run a similar sub
using a different variable which is set to a different column, it goes back
to checking the column in the first sub. I will show the sub that works
(variable is ClosCheck). The second sub is identical except for the variable
is PastCheck. I will be most grateful if you can solve this

Sub MoveCompletedTradesLoop()



'Define Variables
Dim TradesEntered As Range, ClosCheck As Range,



Set ClosCheck = Worksheets("Analysis").Columns(46)



'Define ItmSeq Range
With Sheets("Analysis")
Set TradesEntered = Range("at17:at56")
End With


'Loop: Check for complete trades, copy to Trade History
For Each ClosCheck In TradesEntered
If ClosCheck = "True" Then 'Make this section a Sub and call it here
ClosCheck.EntireRow.Select
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
Else
MsgBox ("That's all") 'Goes with Else. Comment out
Exit Sub 'Goes with Else. Comment it out.
End If
Next 'Ends "For Each" Loop


Set ClosCheck = Nothing
End Sub

SECOND SUB:
Sub MovePastTradesLoop()



'Define Variables
Dim TradesEntered As Range, PastCheck As Range

'
Set PastCheck = Worksheets("Analysis").Columns(48)



'Define ItmSeq Range
With Sheets("Analysis")
Set TradesEntered = Range("at17:at56")
End With
'Loop: Check for complete trades, copy to Trade History
For Each PastCheck In TradesEntered

If PastCheck = "True" Then 'Make this section a Sub and call it here
PastCheck.EntireRow.Select
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
Else '
MsgBox ("OK") 'Goes with Else. Comment out
Exit Sub 'Goes with Else. Comment it out.
End If
Next 'Ends "For Each" Loop


'Protect

End Sub


 
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
Vlookup with variable column reference jenVBA Excel Worksheet Functions 1 March 19th 10 08:57 PM
Cell reference with variable column mjones Excel Worksheet Functions 4 April 25th 08 12:39 AM
Variable column reference in formula excel help acct[_2_] Excel Discussion (Misc queries) 2 January 16th 08 12:31 AM
Copy formula down a column does not use correct cell reference brett Excel Discussion (Misc queries) 1 January 9th 06 04:31 AM
how do I use variable column and rows using other cell reference . Bomber Excel Worksheet Functions 2 July 15th 05 06:39 PM


All times are GMT +1. The time now is 03:00 PM.

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

About Us

"It's about Microsoft Excel"