Copy discontinuous rows in continuous rows

Goalexcel

Board Regular
Joined
Dec 28, 2020
Messages
101
Office Version
  1. 2016
Platform
  1. Windows
I have sheet 1 from column A until column AW, or until count, different rows, to copy to another sheet with macro., in only one column .

Sheet 1 Row A1 = 1, have to copy to sheet 2 Column A and Column B
 

Attachments

  • Test target.png
    Test target.png
    34.2 KB · Views: 11
  • Test result 2.png
    Test result 2.png
    8.5 KB · Views: 10

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You will generally get much faster help if you provide your sample data in a form that can be copied to test with. My signature block below has more details.

Assuming Sheet2 is blank to start with, try this with a copy of your workbook.

VBA Code:
Sub CopyColumns()
  Dim col As Range
  
  With Sheets("Sheet2")
    .Range("B1").Value = 1
    For Each col In Sheets("Sheet1").Range("A1").CurrentRegion.Offset(1).Columns
      col.Copy Destination:=.Range("A" & Rows.Count).End(xlUp).Offset(1)
      .Range("B2:B" & .Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks).Value = col.Cells(0).Value
    Next col
    .Rows(1).Delete
  End With
End Sub
 
Upvote 0
You're welcome. Thanks for the confirmation.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,938
Latest member
Aaliya13

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