#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy Data

Hi All,

I have several worksheets in my workbook.
i want to copy filtered data(if field 4 ="N") from each
sheet based on the sheet name (if the sheet name
contains "02") to last sheet (sheet45)

how can I do this using code?

Thanks
Mas
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Data

Sub CurMonth()
Dim rng as Range, sh as Worksheet
set rng = Sheets("CasCrd").Rows("2:2")
Sheets("CasCrd").Range(rng, rng.End(xlDown)).Delete Shift:=xlUp

For Each Sh In WorkSheets
If Instr(1,Sh.Name, Right( _
Sheets("Interface").[C2],2),vbTextCompare) 0 then
sh.Range("A1").AutoFilter Field:=4, Criteria1:="N"
sh.Autofilter.Range.Resize(,42).Offset(1, 0).Copy _
Destination:=Sheets("CasCrd"). _
Range("A65536").End(xlUp).Offset(1, 0)
Sh.AutoFilterMode = False
End If
Next
End Sub

If it doesn't copy the data you expect, then you need to check if what

Right(Sheets("Interface").[C2],2)

produces and if that value is found in any of the sheet names.

--
Regards,
Tom Ogilvy
"Mas" wrote in message
...
Hi All,

I have several worksheets in my workbook.
i want to copy filtered data(if field 4 ="N") from each
sheet based on the sheet name (if the sheet name
contains "02") to last sheet (sheet45)

how can I do this using code?

Thanks
Mas



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy Data

Hi Tom,

Thanks for your reply.

It dont work?!!!

my Right(Sheets("Interface").[C2],2)returns "04"
and I have two sheets named "M04Ca" and "M04Cr"
I am expecting both these sheets to filter and copy data
to last sheet.

thanks again

Mas

-----Original Message-----
Sub CurMonth()
Dim rng as Range, sh as Worksheet
set rng = Sheets("CasCrd").Rows("2:2")
Sheets("CasCrd").Range(rng, rng.End(xlDown)).Delete

Shift:=xlUp

For Each Sh In WorkSheets
If Instr(1,Sh.Name, Right( _
Sheets("Interface").[C2],2),vbTextCompare) 0 then
sh.Range("A1").AutoFilter Field:=4, Criteria1:="N"
sh.Autofilter.Range.Resize(,42).Offset(1, 0).Copy _
Destination:=Sheets("CasCrd"). _
Range("A65536").End(xlUp).Offset(1, 0)
Sh.AutoFilterMode = False
End If
Next
End Sub

If it doesn't copy the data you expect, then you need to

check if what

Right(Sheets("Interface").[C2],2)

produces and if that value is found in any of the sheet

names.

--
Regards,
Tom Ogilvy
"Mas" wrote in

message
...
Hi All,

I have several worksheets in my workbook.
i want to copy filtered data(if field 4 ="N") from each
sheet based on the sheet name (if the sheet name
contains "02") to last sheet (sheet45)

how can I do this using code?

Thanks
Mas



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Data

The code worked fine for me. Are you sure the names of the Sheets have Zero
4 and not the letter O.

--
Regards
Tom Ogilvy

"Mas" wrote in message
...
Hi Tom,

Thanks for your reply.

It dont work?!!!

my Right(Sheets("Interface").[C2],2)returns "04"
and I have two sheets named "M04Ca" and "M04Cr"
I am expecting both these sheets to filter and copy data
to last sheet.

thanks again

Mas

-----Original Message-----
Sub CurMonth()
Dim rng as Range, sh as Worksheet
set rng = Sheets("CasCrd").Rows("2:2")
Sheets("CasCrd").Range(rng, rng.End(xlDown)).Delete

Shift:=xlUp

For Each Sh In WorkSheets
If Instr(1,Sh.Name, Right( _
Sheets("Interface").[C2],2),vbTextCompare) 0 then
sh.Range("A1").AutoFilter Field:=4, Criteria1:="N"
sh.Autofilter.Range.Resize(,42).Offset(1, 0).Copy _
Destination:=Sheets("CasCrd"). _
Range("A65536").End(xlUp).Offset(1, 0)
Sh.AutoFilterMode = False
End If
Next
End Sub

If it doesn't copy the data you expect, then you need to

check if what

Right(Sheets("Interface").[C2],2)

produces and if that value is found in any of the sheet

names.

--
Regards,
Tom Ogilvy
"Mas" wrote in

message
...
Hi All,

I have several worksheets in my workbook.
i want to copy filtered data(if field 4 ="N") from each
sheet based on the sheet name (if the sheet name
contains "02") to last sheet (sheet45)

how can I do this using code?

Thanks
Mas



.



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
How copy none excel data & paste in 2007 without overwriting data Wakefootin Excel Discussion (Misc queries) 2 October 8th 09 12:15 AM
filted data, copy and paste a col. puts data in wrong row how fix chris_fig New Users to Excel 1 October 16th 06 04:26 PM
Retrieve multiple data rows data from a very long list and copy t mathew Excel Discussion (Misc queries) 1 September 13th 06 08:24 PM
How do I copy data from main frame computer and keep data in cell Doug Excel Worksheet Functions 1 May 30th 06 05:15 PM
Copy old Data from web query while keeping previous days data DRobidoux Excel Worksheet Functions 0 March 22nd 06 01:56 PM


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

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"