View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default variable doesn't reference correct column

Perhaps due to not having a dot in front of the range in your with. Woudn't
matter when doing from the active sheet but would if on a different sheet.
It appears that you could use the same macro with a variable for the column

I did NOT test this

Sub MoveCompletedTradesLoop()
myoffset=0
'or an input box asking for the offset
'myoffset=inputbox("Enter column offset such as 0 or 1")

'Define Variables
Dim TradesEntered As Range, Check As Range,
Set Check = Worksheets("Analysis").Columns(45) .offset(,myoffset)

'Define ItmSeq Range
set tradesentered =Sheets("Analysis").Range("at17:at56")
For Each Check In TradesEntered
If Check = "True" Then
Check.EntireRow.Copy
Sheets("TradeHistory").Range("A4").End(xlDown). _
Offset(1, myoffset).PasteSpecial Paste:=xlPasteValues
end if
Next
End Sub





--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Andyjim" wrote in message
...
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