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
32,288
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
32,288
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,082,168
Messages
5,363,537
Members
400,747
Latest member
monty_gl

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top