I am looking for vba code filter data to copy and paste in same sheet

santoshloka

Board Regular
Joined
Aug 31, 2017
Messages
125
Private Sub CommandButton1_Click()
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To a
If Worksheets("sheet1").Cells(i, 6).Value = "x" Then


Worksheets("Sheet1").Rows(i).Copy
Worksheets("Sheet1").Cells.field = 10
b = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet1").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("sheet1").Activate
End If
Next i
Application.CutCopyMode = False


ThisWorkbook.Worksheets("sheet1").Cells(1, 1).Select
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try:
Code:
Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim bottomF As Long
    bottomF = Sheets("Sheet1").Range("F" & Rows.Count).End(xlUp).Row
    Sheets("Sheet1").Range("F1:F" & bottomF).AutoFilter Field:=1, Criteria1:="x"
    Sheets("Sheet1").Range("F2:F" & bottomF).SpecialCells(xlCellTypeVisible).EntireRow.Copy Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
    If Sheets("Sheet1").FilterMode Then Sheets("Sheet1").ShowAllData
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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