Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Copying certains rows to certain worksheets.

I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copying certains rows to certain worksheets.

Try thiis

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With


"Ron" wrote:

I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Copying certains rows to certain worksheets.

Joel,

It looks like it would work, however, I have 2 problems.

1. While I try to compile, it points to "LastRow =" and says Compile Error,
Argument not optional.
I changed the name to OldRow and it worked. Not sure why.

2. After fixing that, I get to "DestSht = Sheets("TS")" and it says Runtime
error 438, Object doesn't support this property or method.
I changed DestSht to Dsht and it didn't help.

I'm stumped.

Ron

"Joel" wrote:

Try thiis

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With


"Ron" wrote:

I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copying certains rows to certain worksheets.

I didn't know the amount of experience you had with macros. I made one
change below seting DestSht to a sheet name. change to the correct sheet
name you are using.

row.Count should work. I suspect you don't have all the proper settint in
excel check these options

1) On worksheet menu Tools - OPtions - addin

Make sure these two itmes are checked
a) Analysis ToolPak
b) Analysis Toolpak - VBA

2) On VBA menu tools - References make sure these 4 items are checked

a) Visual Basic for Applications
b) Microsoft Excel 10.0 Object library (or latest on your PC)
c) OLE Automation
d) Microsoft Office 10.0 Object Library

These are the standard items that normally are selected with excel.
Sometimes they get unchecked.



Sub test()

Set DestSht = Sheets("Sheet2")

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With

End Sub


"Ron" wrote:

Joel,

It looks like it would work, however, I have 2 problems.

1. While I try to compile, it points to "LastRow =" and says Compile Error,
Argument not optional.
I changed the name to OldRow and it worked. Not sure why.

2. After fixing that, I get to "DestSht = Sheets("TS")" and it says Runtime
error 438, Object doesn't support this property or method.
I changed DestSht to Dsht and it didn't help.

I'm stumped.

Ron

"Joel" wrote:

Try thiis

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With


"Ron" wrote:

I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.

  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Copying certains rows to certain worksheets.

Joel,

All my options were set right...using 2007, so object library is 12.
This is what I did to get it working, based on what you said.
Set DestSht1 = Sheets("TS")
Set DestSht2 = Sheets("CS")
Set DestSht3 = Sheets("Abuse")
Set DestSht4 = Sheets("SADMIN")

Then, in each case I did: Set DestSht = DestSht1 (or 2 or 3 or 4)

Not sure if I needed all that, but it worked.

My experience is chopping all these responses apart and making them work
somehow.

I appreciate what you sent...all you guys are great teachers.

Ron

"Joel" wrote:

I didn't know the amount of experience you had with macros. I made one
change below seting DestSht to a sheet name. change to the correct sheet
name you are using.

row.Count should work. I suspect you don't have all the proper settint in
excel check these options

1) On worksheet menu Tools - OPtions - addin

Make sure these two itmes are checked
a) Analysis ToolPak
b) Analysis Toolpak - VBA

2) On VBA menu tools - References make sure these 4 items are checked

a) Visual Basic for Applications
b) Microsoft Excel 10.0 Object library (or latest on your PC)
c) OLE Automation
d) Microsoft Office 10.0 Object Library

These are the standard items that normally are selected with excel.
Sometimes they get unchecked.



Sub test()

Set DestSht = Sheets("Sheet2")

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With

End Sub


"Ron" wrote:

Joel,

It looks like it would work, however, I have 2 problems.

1. While I try to compile, it points to "LastRow =" and says Compile Error,
Argument not optional.
I changed the name to OldRow and it worked. Not sure why.

2. After fixing that, I get to "DestSht = Sheets("TS")" and it says Runtime
error 438, Object doesn't support this property or method.
I changed DestSht to Dsht and it didn't help.

I'm stumped.

Ron

"Joel" wrote:

Try thiis

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With


"Ron" wrote:

I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Copying certains rows to certain worksheets.

Here are two slightly different versions or the macro that might work for you

Sub test()

Set SourceSht = activesheet
SHtNames = Array("TS","CS","Abuse","SADMIN")

for each sht in ShtNames
Set DestSht = Sheets(Sht)

With SourceSht
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With
next Sht
End Sub

Sub test()

Set SourceSht = activesheet

for each sht in Sheets
if Sht.name < SourceSht.name then
Set DestSht = Sheets(Sht)

With SourceSht
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With
end if
next sht
End Sub


"Ron" wrote:

Joel,

All my options were set right...using 2007, so object library is 12.
This is what I did to get it working, based on what you said.
Set DestSht1 = Sheets("TS")
Set DestSht2 = Sheets("CS")
Set DestSht3 = Sheets("Abuse")
Set DestSht4 = Sheets("SADMIN")

Then, in each case I did: Set DestSht = DestSht1 (or 2 or 3 or 4)

Not sure if I needed all that, but it worked.

My experience is chopping all these responses apart and making them work
somehow.

I appreciate what you sent...all you guys are great teachers.

Ron

"Joel" wrote:

I didn't know the amount of experience you had with macros. I made one
change below seting DestSht to a sheet name. change to the correct sheet
name you are using.

row.Count should work. I suspect you don't have all the proper settint in
excel check these options

1) On worksheet menu Tools - OPtions - addin

Make sure these two itmes are checked
a) Analysis ToolPak
b) Analysis Toolpak - VBA

2) On VBA menu tools - References make sure these 4 items are checked

a) Visual Basic for Applications
b) Microsoft Excel 10.0 Object library (or latest on your PC)
c) OLE Automation
d) Microsoft Office 10.0 Object Library

These are the standard items that normally are selected with excel.
Sometimes they get unchecked.



Sub test()

Set DestSht = Sheets("Sheet2")

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With

End Sub


"Ron" wrote:

Joel,

It looks like it would work, however, I have 2 problems.

1. While I try to compile, it points to "LastRow =" and says Compile Error,
Argument not optional.
I changed the name to OldRow and it worked. Not sure why.

2. After fixing that, I get to "DestSht = Sheets("TS")" and it says Runtime
error 438, Object doesn't support this property or method.
I changed DestSht to Dsht and it didn't help.

I'm stumped.

Ron

"Joel" wrote:

Try thiis

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With


"Ron" wrote:

I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.

  #7   Report Post  
Posted to microsoft.public.excel.programming
a a a a is offline
external usenet poster
 
Posts: 1
Default Copying certains rows to certain worksheets.

On Aug 20, 11:07*pm, Ron wrote:
I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.


Hi,

try using GemBox.Spreadsheet component. It is very easy to use and
works very fast.
http://www.gemboxsoftware.com/GBSpreadsheet.htm
  #8   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Copying certains rows to certain worksheets.

Thanks - I'll play with them and see what I can do with them. I have it
working now.

I'm doing a similar thing on my destination sheets, finding a value in a
column and want to cut it and put it in a third sheet.

Case doesn't seem to be the best fit for that as it finds what I want, but
on all the other rows, it wants a valid destination sheet also.

Any quick and dirty solutions to do that? I'm sure I can use a clunky if
loop, but that is not efficient.

Again, I can't thank you enough.

Ron

"Joel" wrote:

Here are two slightly different versions or the macro that might work for you

Sub test()

Set SourceSht = activesheet
SHtNames = Array("TS","CS","Abuse","SADMIN")

for each sht in ShtNames
Set DestSht = Sheets(Sht)

With SourceSht
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With
next Sht
End Sub

Sub test()

Set SourceSht = activesheet

for each sht in Sheets
if Sht.name < SourceSht.name then
Set DestSht = Sheets(Sht)

With SourceSht
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With
end if
next sht
End Sub


"Ron" wrote:

Joel,

All my options were set right...using 2007, so object library is 12.
This is what I did to get it working, based on what you said.
Set DestSht1 = Sheets("TS")
Set DestSht2 = Sheets("CS")
Set DestSht3 = Sheets("Abuse")
Set DestSht4 = Sheets("SADMIN")

Then, in each case I did: Set DestSht = DestSht1 (or 2 or 3 or 4)

Not sure if I needed all that, but it worked.

My experience is chopping all these responses apart and making them work
somehow.

I appreciate what you sent...all you guys are great teachers.

Ron

"Joel" wrote:

I didn't know the amount of experience you had with macros. I made one
change below seting DestSht to a sheet name. change to the correct sheet
name you are using.

row.Count should work. I suspect you don't have all the proper settint in
excel check these options

1) On worksheet menu Tools - OPtions - addin

Make sure these two itmes are checked
a) Analysis ToolPak
b) Analysis Toolpak - VBA

2) On VBA menu tools - References make sure these 4 items are checked

a) Visual Basic for Applications
b) Microsoft Excel 10.0 Object library (or latest on your PC)
c) OLE Automation
d) Microsoft Office 10.0 Object Library

These are the standard items that normally are selected with excel.
Sometimes they get unchecked.



Sub test()

Set DestSht = Sheets("Sheet2")

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With

End Sub


"Ron" wrote:

Joel,

It looks like it would work, however, I have 2 problems.

1. While I try to compile, it points to "LastRow =" and says Compile Error,
Argument not optional.
I changed the name to OldRow and it worked. Not sure why.

2. After fixing that, I get to "DestSht = Sheets("TS")" and it says Runtime
error 438, Object doesn't support this property or method.
I changed DestSht to Dsht and it didn't help.

I'm stumped.

Ron

"Joel" wrote:

Try thiis

With ActiveSheet
RowCount = 2
Do While .Range("I" & RowCount) < ""
Select Case .Range("I" & RowCount)

Case "AA", "AB", "XY"
DestSht = Sheets("TS")

Case "AC", "DF", "SS"
DestSht = Sheets("CS")

Case "XX"
DestSht = Sheets("XX")
End Select

LastRow = DestSht.Range("A" & Rows.Count).End(xlUp).Row
Newrow = LastRow + 1
.Rows(RowCount).Copy _
Destination:=DestSht.Rows(Newrow)

RowCount = RowCount + 1
Loop

End With


"Ron" wrote:

I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.

  #9   Report Post  
Posted to microsoft.public.excel.programming
Ron Ron is offline
external usenet poster
 
Posts: 250
Default Copying certains rows to certain worksheets.

a a,

Looks interesting. I'll take a look at it. Thanks.

"a a" wrote:

On Aug 20, 11:07 pm, Ron wrote:
I have a sheet with 14 columns of data. Up to 3000 rows, counting a header row.
Column I has a key that I look at to determine which other worksheet to copy
the data to.
For instance, rows with AA, AB, and XY (in column I)I need to copy to a
Sheet named TS.
Rows with AC, DF, SS I need to copy to a Sheet named CS.
And Rows with XX I need to copy to a Sheet named XX.
Of course, it has to copy to the next blank row on each sheet, so all of the
AA's, AB's and XY's are on sheet TS.
Etc.


Hi,

try using GemBox.Spreadsheet component. It is very easy to use and
works very fast.
http://www.gemboxsoftware.com/GBSpreadsheet.htm

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
Copying header rows and inserting them into all worksheets mattmac Excel Programming 6 March 28th 07 09:10 PM
Copying multiple rows to other worksheets (but amount of rows varies) - How? David Smithz Excel Discussion (Misc queries) 1 June 18th 06 04:31 PM
Copying rows to different worksheets based on a cells value DanSmoach Excel Programming 2 May 8th 06 06:32 PM
Copying random rows to other worksheets SusieQ[_7_] Excel Programming 0 February 17th 06 02:52 PM
copying cells into different rows in different worksheets stephanie Excel Programming 2 November 29th 04 03:29 PM


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