Change VBA to not include headers

thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
361
Office Version
  1. 365
Platform
  1. Windows
Hi Guys, i have found some code and adapted and it works great. However, i'd like to change it so it does not copy and paste the headers. Can you help?

Thanks

VBA Code:
Sub Test()


Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Table1") '<== Sheet that has raw data
Dim LRow As Long, Found As Range
Dim lastRow As String
Dim lastRow2 As String
lastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
lastRow2 = Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row

Set Found = ws.Range("A1:HE1").Find("New or Used") '<== Header name to search for
If Not Found Is Nothing Then
LRow = ws.Cells(ws.Rows.Count, Found.Column).End(xlUp).Row
ws.Range(ws.Cells(1, Found.Column), ws.Cells(LRow, Found.Column)).Copy
Sheets("Sheet1").Range("A" & lastRow).PasteSpecial xlPasteValues '<== Sheet to paste data
End If


ws.Activate
ActiveSheet.Select

Set Found = ws.Range("A1:HE1").Find("Total Profit") '<== Header name to search for)
If Not Found Is Nothing Then
LRow = ws.Cells(ws.Rows.Count, Found.Column).End(xlUp).Row
ws.Range(ws.Cells(1, Found.Column), ws.Cells(LRow, Found.Column)).Copy
Sheets("Sheet1").Range("B" & lastRow).PasteSpecial xlPasteValues '<== Sheet to paste data

End If

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Roger Govier

Active Member
Joined
Jun 19, 2002
Messages
303
Hi

Just amend this line of code
ws.Range(ws.Cells(1, Found.Column), ws.Cells(LRow, Found.Column)).Copy

to
ws.Range(ws.Cells(2, Found.Column), ws.Cells(LRow, Found.Column)).Copy
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,938
Office Version
  1. 365
Platform
  1. Windows
Make this change
Rich (BB code):
ws.Range(ws.Cells(2, Found.Column), ws.Cells(LRow, Found.Column)).Copy
 

Fluff

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

Forum statistics

Threads
1,148,187
Messages
5,745,230
Members
423,936
Latest member
Conservatopia

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