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: 4
Default Help? Anyone see problem with this macro? Way to condense it?

I have written the following macro (some portions borrowed) and the
first two (2) subs run fine and move all of their data to their
respective sheets, but the the third (3rd) only does half the lines,
then if you run it again, half of what is left, and a third time
through completes. I have beat my head against the wall in an attempt
to figure out why 2/3's of it works wonderful and the last 1/3 is not
working? Any ideas? (Thanks in advance)
================================================== ================

Option Explicit
Sub CopyRows1()
Dim rng As Range
Dim cl As Range
Dim str As String

Set rng = ActiveSheet.Range("a2:a6500") 'Range to search (used
range)
str = "X" 'What to look for
For Each cl In rng 'Check each cell

If cl.Text = str Then
'If cell contains the correct value copy it to next empty
row on sheet 2 & delete the row sheet 1
cl.EntireRow.Copy Destination:=Sheet2.Cells(Rows.Count,
1).End(xlUp).Offset(1, 0)
cl.EntireRow.Delete
End If
Next cl
'Run ["Sheet1.CopyRows2"]
End Sub
-----------------------------------------------------------------------------------------------------------------
Sub CopyRows2()
Dim rng As Range
Dim cl As Range
Dim str As String

Set rng = ActiveSheet.Range("a2:a6500") 'Range/Column to search
str = "Y" 'What to look for
For Each cl In rng 'Check each cell

If cl.Text = str Then
'If cell contains the correct value copy it to next empty
row on sheet 3 & delete the row sheet 1
cl.EntireRow.Copy Destination:=Sheet3.Cells(Rows.Count,
1).End(xlUp).Offset(1, 0)
cl.EntireRow.Delete
End If
Next cl
'Run ["Sheet1.CopyRows3"]
End Sub
-----------------------------------------------------------------------------------------------------------
Sub CopyRows3()
Dim rng As Range
Dim cl As Range
Dim str As String

Set rng = ActiveSheet.Range("a2:a50") 'Range/Column to search
str = "A" 'What to look for
For Each cl In rng 'Check each cell

If cl.Text = str Then
'If cell contains the correct value copy it to next empty
row on sheet 4 & delete the row sheet 1
cl.EntireRow.Copy Destination:=Sheet4.Cells(Rows.Count,
1).End(xlUp).Offset(1, 0)
cl.EntireRow.Delete
End If
Next cl
'Run ["Sheet1.CopyRows4"]
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
Condense a formula gotroots Excel Worksheet Functions 1 December 16th 09 03:25 PM
condense List Lita Excel Worksheet Functions 5 November 21st 08 06:00 AM
Condense Code Nigel Excel Programming 2 December 22nd 05 11:59 PM
Condense formula Derek Y via OfficeKB.com Excel Worksheet Functions 9 November 18th 05 03:00 AM
Help to condense a formula GerryK Excel Worksheet Functions 1 June 29th 05 08:19 PM


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