Remove Header Row

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am running a macro to move data from one sheet to another workbook, however, right now when it transfers the info over the column header is also with the data, what can i do to my code to get the column header removed?

VBA Code:
  Set wsCopy = Workbooks("New Data.xlsx").Worksheets("Session1")
  Set wsDest = Workbooks("Reports.xlsm").Worksheets("All Data")
    
  'Find last used row in the copy range based on data in column A
  lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
 
  'Copy & Paste Data
   wsCopy.Range("A10:X" & lCopyLastRow).Copy _
            wsDest.Range("A" & lDestLastRow)
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Is the header row in row 10?
 
Upvote 0
In that case your code should work, unless there is nothing below A8
 
Upvote 0
How about
VBA Code:
  If lcopylastrow > 9 Then
      wsCopy.Range("A10:X" & lcopylastrow).Copy _
               wsDest.Range("A" & lDestLastRow)
  End If
 
Upvote 0
Solution
How about
VBA Code:
  If lcopylastrow > 9 Then
      wsCopy.Range("A10:X" & lcopylastrow).Copy _
               wsDest.Range("A" & lDestLastRow)
  End If
I hate to throw one last curveball at you with this, all these sheets have a minimized 9th row that is empty if there is no data, otherwise the data starts on the 9th row, but the header is always on row 8, would this code work for that instance?
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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