hi I'm new here just trying to help by making some improvement changes [image: 😊]
*Sub Copy_Filtered_Data()* *'know line os last row* *Dim last_row* *last_row = Range("s64000").End(xlUp).Row 'using in excel 97 or 2010* *'last_row = Range("s1048576").End(xlUp).Row 'using only in excel 2010* *'if dont have data on S, you will get a bug on autofilter* *if last_row = 2 then* * msgbox "You dont have data on colunm S"* * exit sub* *end if* *'know the desktop folder ( without / in the end!! )* *desktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")* *'remove filter ( if aredy is you will get a bug )* *ActiveSheet.AutoFilterMode = False* *'----------------------------------------------------------------------------* *' Filter data to remove rows with blank values in column "S"* *'----------------------------------------------------------------------------* * ActiveSheet.Range("$A$1:$BV$" & last_row).AutoFilter Field:=19, Criteria1:="<>"* *'----------------------------------------------------------------------------* *' Select rows from Cell A1 to Cell XFD51 and copy to Clipboard* *'----------------------------------------------------------------------------* * Range("BV1").Activate* * Range("A1:BV" **& last_row**).Copy* *'----------------------------------------------------------------------------* *' Open New Workbook and paste data from Clipboard* *'----------------------------------------------------------------------------* * Workbooks.Add* * Range("A1").Select* * ActiveSheet.Paste* * Application.CutCopyMode = False* *'----------------------------------------------------------------------------* *' Save new file as "thisisthenameofanewworkbook" and close* *'----------------------------------------------------------------------------* * ActiveWorkbook.SaveAs _* * Filename:=desktop & "\thisisthenameofanewworkbook.xlsb", _* * FileFormat:=xlExcel12, _* * CreateBackup:=False* * Workbooks("thisisthenameofanewworkbook.xlsb").Close* *End Sub* Em quarta-feira, 7 de outubro de 2015 08:54:21 UTC-3, Paul Schreiner escreveu: > > Mr PRADEEP, > > Mr. Abhishek may be being a bit "snarky", but he has correctly answered > your question. > > Yes, "we" can. > > But because there's not NEARLY enough information in your question, we'd > either have to begin asking for lots more information, or make assumptions. > > You didn't give us much to go on. > - You're filtering column "S", so you've got between 19 and 16,384 columns > If you're using Excel 2007 or newer. > To be safe, perhaps we should stop at column 256 (IV) > For my example, I'll "assume" you have 74 columns. just because I do. > > - You said you "can" have 50 lines (rows?) > Does that mean 50 rows AFTER column S is filtered? > Or you have 50 rows TOTAL (including the header?) > My sample data has 21,481 rows, so I'll use that. > > - You said "with 10 names" > What are "names"? Named Ranges? values in column "S"? (why would that > matter?) > I have no idea, so I'll disregard that. > > - You're "filtering" column "S"... how? > With nothing else to go on, I'll "assume" you're removing blank values. > > - You want to "paste" the filtered data to a "new workbook" and "save it". > Since I don't know what filename you want, I'll call it > "thisisthenameofanewworkbook" (because I can be snarky too!) > Since you didn't mention a specific file type, > I'll save it as an .xlsb file because I prefer that type. > > - In the title of your post, you said "save it on desktop". > So at least we have a location. > > - Now typically, I prefer NOT to use the Windows clipboard for copy/paste. > It's CPU intensive, and CAN be damaged if you happen to be using it for > something else while your program is running. > But this program seems simple enough that it ought to be safe to use. > > So, with the help of a macro recorder, and sample data I copied from a > random selection of data in one of my files, I came up with this macro > (comments added for clarity) > > Sub Copy_Filtered_Data() > > '---------------------------------------------------------------------------- > ' Filter data to remove rows with blank values in column "S" > > '---------------------------------------------------------------------------- > ActiveSheet.Range("$A$1:$BV$21481").AutoFilter Field:=19, > Criteria1:="<>" > > '---------------------------------------------------------------------------- > ' Select rows from Cell A1 to Cell XFD51 and copy to Clipboard > > '---------------------------------------------------------------------------- > Range("BV51").Activate > Range("A1:BV51").Copy > > '---------------------------------------------------------------------------- > ' Open New Workbook and paste data from Clipboard > > '---------------------------------------------------------------------------- > Workbooks.Add > Range("A1").Select > ActiveSheet.Paste > Application.CutCopyMode = False > > '---------------------------------------------------------------------------- > ' Save new file as "thisisthenameofanewworkbook" and close > > '---------------------------------------------------------------------------- > ActiveWorkbook.SaveAs _ > > Filename:="C:\Users\(*youruseridgoeshere*)\Desktop\thisisthenameofanewworkbook.xlsb", > > _ > FileFormat:=xlExcel12, _ > CreateBackup:=False > Workbooks("thisisthenameofanewworkbook.xlsb").Close > > End Sub > > I hope this helps. > > *Paul* > > > ----------------------------------------- > > > > > > > > *“Do all the good you can,By all the means you can,In all the ways you > can,In all the places you can,At all the times you can,To all the people > you can,As long as ever you can.” - John Wesley* > ----------------------------------------- > > ------------------------------ > *From:* Abhishek Jain <abhish...@gmail.com <javascript:>> > *To:* MS EXCEL AND VBA MACROS <excel-...@googlegroups.com <javascript:>> > *Sent:* Wednesday, October 7, 2015 2:37 AM > *Subject:* Re: $$Excel-Macros$$ filter and copy/paste in new workbook and > save it on desktop > > Yes, we can. > > > > On Sun, Oct 4, 2015 at 3:47 PM, PRADEEP KUMAR KOKNE <pradeep...@gmail.com > <javascript:>> wrote: > > Hello all, > > Can you write code for to filter(Column S)-> select the complete visible > data and paste it in new workbook and save it. > > Example: Column S can have 50 lines data with 10 names > > > Thanks > > -- > Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s > =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ > https://www.facebook.com/discussexcel > > FORUM RULES > > 1) Use concise, accurate thread titles. Poor thread titles, like Please > Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice > will not get quick attention or may not be answered. > 2) Don't post a question in the thread of another member. > 3) Don't post questions regarding breaking or bypassing any security > measure. > 4) Acknowledge the responses you receive, good or bad. > 5) Jobs posting is not allowed. > 6) Sharing copyrighted material and their links is not allowed. > > NOTE : Don't ever post confidential data in a workbook. Forum owners and > members are not responsible for any loss. > --- > You received this message because you are subscribed to the Google Groups > "MS EXCEL AND VBA MACROS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to excel-macros...@googlegroups.com <javascript:>. > To post to this group, send email to excel-...@googlegroups.com > <javascript:>. > Visit this group at http://groups.google.com/group/excel-macros. > For more options, visit https://groups.google.com/d/optout. > > > -- > Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s > =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ > https://www.facebook.com/discussexcel > > FORUM RULES > > 1) Use concise, accurate thread titles. Poor thread titles, like Please > Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice > will not get quick attention or may not be answered. > 2) Don't post a question in the thread of another member. > 3) Don't post questions regarding breaking or bypassing any security > measure. > 4) Acknowledge the responses you receive, good or bad. > 5) Jobs posting is not allowed. > 6) Sharing copyrighted material and their links is not allowed. > > NOTE : Don't ever post confidential data in a workbook. Forum owners and > members are not responsible for any loss. > --- > You received this message because you are subscribed to the Google Groups > "MS EXCEL AND VBA MACROS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to excel-macros...@googlegroups.com <javascript:>. > To post to this group, send email to excel-...@googlegroups.com > <javascript:>. > Visit this group at http://groups.google.com/group/excel-macros. > For more options, visit https://groups.google.com/d/optout. > > > -- Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ https://www.facebook.com/discussexcel FORUM RULES 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Jobs posting is not allowed. 6) Sharing copyrighted material and their links is not allowed. NOTE : Don't ever post confidential data in a workbook. Forum owners and members are not responsible for any loss. --- You received this message because you are subscribed to the Google Groups "MS EXCEL AND VBA MACROS" group. To unsubscribe from this group and stop receiving emails from it, send an email to excel-macros+unsubscr...@googlegroups.com. To post to this group, send email to excel-macros@googlegroups.com. Visit this group at http://groups.google.com/group/excel-macros. For more options, visit https://groups.google.com/d/optout.