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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
actually i should add to that, the first column to be copied will always have data. the other columns will have either data or #VALUE error, is there a way of not copying the #VALUE error cells as well?
 
Upvote 0
Do the other columns contain formulae?
 
Upvote 0
Do the other columns contain formulae?


yes, all cells contain an if statement beginning =IF(equals_data!E2>0," although the source cells have an ' in it when no number which i think is causing the <man looking="" up="" from="" a="" page="" that="" also="" has="" lookup.="" if="" the="" value="" is="" greater="" than="" "0"="" it="" works="" but="" its="" blank,="" cell="" contains="" '="" which="" i="" think="" causing="" <a="" href="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=VALUE" target="_blank">#VALUE issue.</man>
 
Last edited:
Upvote 0
When posting formulae using > or < symbols please put a space either side of them, alternatively click Go Advanced & select HTML off.

Do you just want to copy the values?
 
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 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
   Sheets("XML").Range("A1").Resize(j).Value = Application.Transpose(Nary)
End Sub
 
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 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
   Sheets("XML").Range("A1").Resize(j).Value = Application.Transpose(Nary)
End Sub


wow, i dont understand any of that :D

but unfortunately i get a run time error 13 type mismatch.

am i using this incorrectly?
 
Upvote 0
What line gives that error?
Also, roughly, how many rows do you have?
 
Upvote 0
What line gives that error?

Debug runs through until J=752

then fails on

Sheets("XML").Range("A1").Resize(j).Value = Application.Transpose(Nary)



Also, roughly, how many rows do you have?

there will be less than one hundred lines in each column. this doesnt copy any at the moment.
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,696
Members
448,293
Latest member
jin kazuya

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