Find, Cut and Paste Macro

Realrookie

New Member
Joined
Apr 25, 2022
Messages
9
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
Hello all,

A little experience with VBA.
I did search the forum and found several similar posts but I cannot modify any opf them due to lacking knowledge.

I have a master sheet with over 30k lines of data. From here in Sheet1, Column B i have to find the customer reference, cut that row (or rows if multiple available) and paste it in the Sheet2 on the next empty cell in Column A.

I have seen several macro's on this forum that all use pre-defined search terms but none that has a find "Box".

Any help or pointers would be greatly apreciated.

Red
 
I figured it out:
VBA Code:
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial (xlPasteValues)

Thank you very much for your code
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Scrap that. I changed copy to cut and it now fails.
Code:
Sub CopyPaste2()
Dim lr&
Worksheets("Sheet1").Activate
lr = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.AutoFilterMode = False
Range("A1:H" & lr).AutoFilter field:=2, Criteria1:=InputBox("Customer reference: ")
Range("A2:H" & lr).SpecialCells(xlCellTypeVisible).Cut
Worksheets("Sheet2").Activate
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial (xlPasteValues)
'Sheets.Add after:=Worksheets("Sheet1")
'ActiveSheet.PasteSpecial (xlPasteValues)
Worksheets("Sheet1").AutoFilterMode = False
Application.CutCopyMode = True
End Sub
 
Upvote 0
VBA Code:
Option Explicit
Sub CopyPaste()
Dim lr&
Worksheets("Sheet1").Activate
lr = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.AutoFilterMode = False
Range("A1:H" & lr).AutoFilter field:=2, Criteria1:=InputBox("Customer reference: ")
Range("A1:H" & lr).SpecialCells(xlCellTypeVisible).Copy
Sheets.Add after:=Worksheets("Sheet1")
ActiveSheet.Cells(1, 1).PasteSpecial (xlPasteValues)
Worksheets("Sheet1").AutoFilterMode = False
Application.CutCopyMode = False
End Sub
I changed the code to the following (and it works as long as data is visible):

VBA Code:
Sub CopyPaste()
Dim lr&
Worksheets("Sheet1").Activate
lr = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.AutoFilterMode = False
Range("A1:H" & lr).AutoFilter field:=2, Criteria1:=InputBox("Customer reference: ")
Range("B2:H" & lr).SpecialCells(xlCellTypeVisible).Copy
Worksheets("Sheet2").Activate
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial (xlPasteValues)
Worksheets("Sheet1").Activate
    With ActiveSheet.AutoFilter.Range
    .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    End With
Worksheets("Sheet1").AutoFilterMode = False
Application.CutCopyMode = False
End Sub

My final question: Is it possible to have the macro stop when no data is available? When I tried to run the code for a 2nd time with the same filter as the 1st, it errors out. Basically when there is no data available, it stops.
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,636
Members
449,043
Latest member
farhansadik

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