copy 4 columns into one, missing empty or #VALUE! cells

dappy

Board Regular
Joined
Apr 23, 2018
Messages
124
Office Version
  1. 2013
Platform
  1. Windows
Hi folks,

i have 4 columns of data that vary in length to copy to one column and i cant figure out a loop to get the 2,3 or 4 columns copied to the bottom of the first

i have this so far

Dim x As Integer
Dim y As Integer
x = 1
y = 2
Do Until Worksheets("Sheet4").Range("A" & x) = ""
Worksheets("XML").Range("A" & y) = Worksheets("Sheet4").Range("A" & x)
y = y + 1
x = x + 1
Loop

any guidance much appreciated.

Carl
 
Try replacing that last line with
Code:
   For r = 1 To j
      Sheets("XML").Range("A1").Offset(r).Value = Nary(r)
   Next r
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try replacing that last line with
Code:
   For r = 1 To j
      Sheets("XML").Range("A1").Offset(r).Value = Nary(r)
   Next r


thanks that did populated the first column of sheet4 into XML sheet but not columns B, c and d. is this right?

Sub CopyCols()
Dim Ary As Variant, Nary As Variant
Dim r As Long, c As Long, j As Long
Ary = Intersect(Sheets("sheet4").UsedRange, Sheets("sheet4").Range("A:D"))
ReDim Nary(1 To UBound(Ary, 1) * 4)
For c = 1 To UBound(Ary, 2)
For r = 1 To UBound(Ary, 1)
If Not IsEmpty(Ary(r, c)) And Not IsError(Ary(r, c)) Then
j = j + 1
Nary(j) = Ary(r, c)
End If
Next r
Next c
For r = 1 To j
Sheets("XML").Range("A1").Offset(r).Value = Nary(r)
Next r
End Sub
 
Upvote 0
Cols B to D should be in col A underneath the col A data.
 
Upvote 0
Pu this message box in as shown
Code:
   Next C
  [COLOR=#ff0000] MsgBox UBound(ary) & vbLf & UBound(Nary) & vbLf & j[/COLOR]
   For R = 1 To j
What does it say?
 
Upvote 0
Pu this message box in as shown
Code:
   Next C
  [COLOR=#ff0000] MsgBox UBound(ary) & vbLf & UBound(Nary) & vbLf & j[/COLOR]
   For R = 1 To j
What does it say?

It shows


190
760
636
 
Upvote 0
Ok, what is the last used cell in sheets XML, colA?
 
Upvote 0
Don't understand what is happening. :(

Would you be willing to upload your file to a share site & provide the link?
 
Upvote 0
How about
Code:
Sub CopyCols()
   Dim ary As Variant, Nary As Variant
   Dim R As Long, C As Long, j As Long
   ary = Intersect(Sheets("sheet4").UsedRange, Sheets("sheet4").Range("A:D"))
   ReDim Nary(1 To UBound(ary, 1) * 4)
   For C = 1 To UBound(ary, 2)
      For R = 1 To UBound(ary, 1)
         If Not IsError(ary(R, C)) Then
            If Not Len(ary(R, C)) = 0 Then
               j = j + 1
               Nary(j) = ary(R, C)
            End If
         End If
      Next R
   Next C
   For R = 1 To j
      Sheets("XML").Range("A1").Offset(R).Value = Nary(R)
   Next R
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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