Note that there are some explanatory texts on larger screens.

plurals
  1. POEXCEL VBA Paste from array, change paste order
    primarykey
    data
    text
    <p>I'm wondering if there is a way that I can choose in wich order my columns will end up in when I run this code. I want the columns to end up in that order they are copied, but they paste in the order they are from the other sheet. I have managed to swap the columns after they are pasted, but it requires so much code and the macro is slow as it is.</p> <pre><code>SearchString = "start" Set aCell = phaseRange.Find(What:=SearchString, LookIn:=xlValues, _ LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) If Not aCell Is Nothing Then Set bCell = aCell ReDim Preserve arrStart(nS) arrStart(nS) = aCell.Row nS = nS + 1 Do While ExitLoop = False Set aCell = phaseRange.FindNext(After:=aCell) If Not aCell Is Nothing Then If aCell.Row = bCell.Row Then Exit Do ReDim Preserve arrStart(nS) arrStart(nS) = aCell.Row nS = nS + 1 Else ExitLoop = True End If Loop Else </code></pre> <p>How I print it out:</p> <pre><code>For i = 1 To nS - 1 Sheets("DataSheet").Select Union(Sheets("raw_list").Cells(arrStart(i), NameCol), Sheets("raw_list").Cells(arrStart(i), PhaseCol), Sheets("raw_list").Cells(arrStart(i), ToStartCol), Sheets("raw_list").Cells(arrStart(i), ToDefineCol), Sheets("raw_list").Cells(arrStart(i), ToMeasureCol), Sheets("raw_list").Cells(arrStart(i), ToAnalyseCol), Sheets("raw_list").Cells(arrStart(i), ToImproveDevCol), Sheets("raw_list").Cells(arrStart(i), ToImproveIndCol), Sheets("raw_list").Cells(arrStart(i), ToControlCol), Sheets("raw_list").Cells(arrStart(i), ToClosedCol)).Copy Cells(r, 1).Select ActiveSheet.Paste With Selection.Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With r = r + 1 Next End If </code></pre> <p>thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload