Combine Data in Multiple Columns Into One Column

usmananyc

New Member
Joined
Jul 21, 2015
Messages
31
Hello Everyone, thank you in advance for your help.

Basically what i am trying to do is copy all data from Columns M to Column T starting from Row 3 and paste it into a new worksheet. The hard part is that some cell values can be blank in between rows. So essentially id like to copy all values without any blanks into the new worksheet. My current script looks at the whole range instead of starting at M3.

If its not too much trouble, id also like to output the newly pasted data to a .SQL file and save it in a certain directory.

Code:
Sub CopyData()

' CopyData Macro


Dim x As Integer
Dim y As Integer


x = 1
y = 1


Do Until Worksheets("Datafix").Range("M" & x) = ""
    Worksheets("SQLScript").Range("A" & y) = Worksheets("Datafix").Range("M" & x)
    y = y + 1
    x = x + 1
    
Loop


End Sub

Example:
UpdateStartEndRemoveVolumeCostAppendVoid
ADGD
DG
BD
BGC
C
CG
DD

<tbody>
</tbody>
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,139
Office Version
  1. 365
Platform
  1. Windows
Do those columns contain any formulae?
Also do you want all of them to go to col A?
 

usmananyc

New Member
Joined
Jul 21, 2015
Messages
31
Do those columns contain any formulae?
Also do you want all of them to go to col A?

These columns output a SQL Script from running a macro so it gets output as text i believe, no formulas in the cell itself. And Yes, id like all of them to go to Col A.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,139
Office Version
  1. 365
Platform
  1. Windows
Try this
Code:
Sub CopyColumns()

   Dim Cnt As Long
   
   For Cnt = 13 To 20
      Worksheets("Datafix").Columns(Cnt).SpecialCells(xlConstants).Copy _
         Worksheets("SQLScript").Range("A" & Rows.Count).End(xlUp).Offset(1)
   Next Cnt
End Sub
Unfortunately I cannot help with the 2nd part of your request.
 

usmananyc

New Member
Joined
Jul 21, 2015
Messages
31

ADVERTISEMENT

Try this
Code:
Sub CopyColumns()

   Dim Cnt As Long
   
   For Cnt = 13 To 20
      Worksheets("Datafix").Columns(Cnt).SpecialCells(xlConstants).Copy _
         Worksheets("SQLScript").Range("A" & Rows.Count).End(xlUp).Offset(1)
   Next Cnt
End Sub
Unfortunately I cannot help with the 2nd part of your request.

Wow that works great! Didnt expect it to be such a simple code. Thank you so much! Now i only need this outputed as a .SQL or .TXT file.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,962
Messages
5,599,065
Members
414,281
Latest member
Engjamal2021

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