PC Review


Reply
Thread Tools Rate Thread

Adding criteria to loop

 
 
Andyjim
Guest
Posts: n/a
 
      13th Jan 2008
I submitted this question earlier, but I don't see my post.

This loop works fine. I need to create a similar loop that does the same
thing except instead of copy and pasting, I need it to delete certain ranges
(specifically cells a:f, K:m, and o:s). This probably could be done with
offsets, but is there a better way? Thanks in advance.



Sub MoveCompletedTradesLoop()


Dim TradesEntered As Range, ClosCheck As Range

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


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

If ClosCheck.Value = "True" Then
With ClosCheck
.Worksheet.Select
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
Range("A1").Select
End With
'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 With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      14th Jan 2008
You probably want to clearcontents, not delete cells

clearrow = activecell.row
Range("A" & clearrow & ":F" & clearrow).clearcontents
Range("K" & clearrow & ":M" & clearrow).clearcontents
Range("O" & clearrow & ":S" & clearrow).clearcontents


"Andyjim" wrote:

> I submitted this question earlier, but I don't see my post.
>
> This loop works fine. I need to create a similar loop that does the same
> thing except instead of copy and pasting, I need it to delete certain ranges
> (specifically cells a:f, K:m, and o:s). This probably could be done with
> offsets, but is there a better way? Thanks in advance.
>
>
>
> Sub MoveCompletedTradesLoop()
>
>
> Dim TradesEntered As Range, ClosCheck As Range
>
> With Sheets("Analysis")
> Set TradesEntered = .Range("at17:at56")
> End With
>
>
> 'Loop: Check for complete trades, copy to Trade History
> For X = 1 To TradesEntered.Count
> Set ClosCheck = TradesEntered(X)
>
> If ClosCheck.Value = "True" Then
> With ClosCheck
> .Worksheet.Select
> 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
> Range("A1").Select
> End With
> '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 With Quote
 
Andyjim
Guest
Posts: n/a
 
      14th Jan 2008
Thanks so much Joel...I'll try this

"Joel" wrote:

> You probably want to clearcontents, not delete cells
>
> clearrow = activecell.row
> Range("A" & clearrow & ":F" & clearrow).clearcontents
> Range("K" & clearrow & ":M" & clearrow).clearcontents
> Range("O" & clearrow & ":S" & clearrow).clearcontents
>
>
> "Andyjim" wrote:
>
> > I submitted this question earlier, but I don't see my post.
> >
> > This loop works fine. I need to create a similar loop that does the same
> > thing except instead of copy and pasting, I need it to delete certain ranges
> > (specifically cells a:f, K:m, and o:s). This probably could be done with
> > offsets, but is there a better way? Thanks in advance.
> >
> >
> >
> > Sub MoveCompletedTradesLoop()
> >
> >
> > Dim TradesEntered As Range, ClosCheck As Range
> >
> > With Sheets("Analysis")
> > Set TradesEntered = .Range("at17:at56")
> > End With
> >
> >
> > 'Loop: Check for complete trades, copy to Trade History
> > For X = 1 To TradesEntered.Count
> > Set ClosCheck = TradesEntered(X)
> >
> > If ClosCheck.Value = "True" Then
> > With ClosCheck
> > .Worksheet.Select
> > 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
> > Range("A1").Select
> > End With
> > '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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding criteria to loop Andyjim Microsoft Excel Worksheet Functions 0 13th Jan 2008 08:54 PM
loop on criteria yaniv.dg@gmail.com Microsoft Excel Discussion 3 29th Jul 2006 04:06 PM
Advancing outer Loop Based on criteria of inner loop =?Utf-8?B?RXhjZWxNb25rZXk=?= Microsoft Excel Programming 1 15th Aug 2005 05:23 PM
Problem adding charts using Do-Loop Until loop =?Utf-8?B?Q2hyaXMgQnJvbWxleQ==?= Microsoft Excel Programming 2 23rd May 2005 01:31 PM
3 range criteria for Loop hotherps Microsoft Excel Programming 0 14th Apr 2004 06:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 AM.