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>
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,806
Office Version
365
Platform
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
33,806
Office Version
365
Platform
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
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.
 

Forum statistics

Threads
1,085,718
Messages
5,385,428
Members
401,947
Latest member
dpope10

Some videos you may like

This Week's Hot Topics

Top