Delete all rows after copying in new sheet by vba

m_vishal_c

Board Regular
Joined
Dec 7, 2016
Messages
209
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
HI i need to delete all rows after copying in new sheet.

I am using below code

Code:
last = Sheets(sht).Cells(Rows.Count, "A").End(xlUp).RowSet rng = Sheets(sht).Range("A1:F" & last)
Set rng1 = Worksheets("Need to be removed 0").Range("B2:B4")


'Sheets(sht).Range("F1:F" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("L1"), Unique:=True ''' THIS IS FOR ENTIRE RANGE NOT FOR PERTICULAR VALUE, Macro will create all values's extra sheet




Dim sCriteria As String




For Each x In rng1 


sCriteria = "*" & x.Value & "*"
With rng
    '.AutoFilter Field:=1, Criteria1:="=(x.value)*", Operator:=xlFilterValues
     .AutoFilter Field:=3, Criteria1:=sCriteria, Operator:=xlFilterValues
    .SpecialCells(xlCellTypeVisible).Copy
    Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
    ActiveSheet.Paste
End With
Next x


' Turn off filter
Sheets(sht).AutoFilterMode = False

Heaps thanks
 
Look at my first reply. That line of code should be outside the For ... Next loop.
My understanding is that you want to delete the source, rng. If not, please clarify.

hi, i tried the way you told me but it still does not remove / delete rows from sheet1 and it delete header from Sheet1.

Please guide me. if you want i can upload file for you. Please let me know

thanks
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Please upload the file to a site which doesn't need a password for download. Delete all sensitive data before uploading the file.
 
Upvote 0
There are many sites on the Internet that allow you to upload and share files, such as Dropbox. Please pick one that doesn't require a password for download.
 
Upvote 0
So, you want to delete A1:F3883 in Sheet1 and leave L1:L10 intact?
 
Upvote 0
let me explain. you can see HFC Infill, LOCID, Copper etc unique value. i want to move rows related to those value in by creating new sheet and move those value from sheet1. thanks
 
Upvote 0
let me explain. you can see HFC Infill, LOCID, Copper etc unique value. i want to move rows related to those value in by creating new sheet and move those value from sheet1. thanks

in other way you are right
After copying to new sheet, need to remove those rows from sheet1.
 
Upvote 0
let me explain. you can see HFC Infill, LOCID, Copper etc unique value. i want to move rows related to those value in by creating new sheet and move those value from sheet1. thanks
The command button already does that.
 
Upvote 0
Try this. See if it is what you want. This code deletes those rows that are copied to other sheets and leave uncopied rows intack.

Code:
.............
.............
Sheets(sht).AutoFilterMode = False

[COLOR=#ff0000]rng.EntireRow.Delete[/COLOR]  '<- add this line
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top