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>
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Do those columns contain any formulae?
Also do you want all of them to go to col A?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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