Copy data by autofiltering and pasting to last empty row in another sheet

JasonWilliam

New Member
Joined
May 11, 2021
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I have a sheet named BOM that I copy and paste the data from into a sheet named BOM Data. At the moment I have to physically highlight the data in order to select the range. I would like to just click the button I created and have it copy the Range (If it has a value in it) to the next empty row in my BOM Data sheet. This is my code I have at the moment. Any help would be appreciated. BTW the range is A4:H104...


Private Sub CommandButton1_Click()


Dim xScreenUpdating As Boolean
Dim xPasteSht As Worksheet
Dim xRg As Range
Dim xTxt As String

On Error Resume Next
xTxt = ActiveWindow.RangeSelection.Address

Set xRg = Application.InputBox("Please select a range:", "Transfer Tool", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub

Set xPasteSht = Worksheets("BOM Data")
xScreenUpdating = Application.ScreenUpdating

Application.ScreenUpdating = False
xRg.Copy
xPasteSht.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = xScreenUpdating

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub CommandButton1_Click()
   With Range("A4:H" & Range("A" & Rows.Count).End(xlUp).Row)
      Sheets("BOM Data").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Rows.Count, .Columns.Count).Value = .Value
   End With
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,619
Members
449,039
Latest member
Mbone Mathonsi

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