Change VBA to not include headers

thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
442
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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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
 
Upvote 0
Make this change
Rich (BB code):
ws.Range(ws.Cells(2, Found.Column), ws.Cells(LRow, Found.Column)).Copy
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,027
Members
448,543
Latest member
MartinLarkin

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