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

JasonWilliam

New Member
Joined
May 11, 2021
Messages
4
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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,587
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,147,479
Messages
5,741,383
Members
423,657
Latest member
Medrok2021

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
Top