PDA

View Full Version : [SOLVED:] Re-Arrange Columns after Import



Foncesa
08-28-2022, 03:10 AM
Hi,
I have imported selected columns from CSV file to Temp sheet, in this Temp sheet at the end of imported data one header is also imported with columns mismatched, now after the 2-Header i want to move the 2nd Header Columns from A to E and Column E to A to get data in order.
Some one help to re-arrange the data.

30097

Excel Sheet Attached.

SamT
08-28-2022, 04:47 AM
Record a Macro, Save to My Personal.xlsm
Select the Temp Tab
Select Column A
Ctrl+H to replace "Total" with "OrderDate"
Select Column E
Ctrl+H to replace "OrderDate" with "Total"
Stop recording

Run the saved Macro the next time you import the data

Foncesa
08-28-2022, 05:30 AM
Thanks SamT, this is reordering only Headers but i also want to move the below data and the rows are not defined.

nilem
08-29-2022, 09:58 PM
Hi Foncesa,
try it

Sub ertert()
Dim x, i&, dt, bu As Boolean

With Sheets("Temp")
If .FilterMode Then .ShowAllData
x = .Range("A1:E" & .Cells(Rows.Count, 1).End(xlUp).Row).Value
End With

For i = 1 To UBound(x)
If x(i, 1) = "Total" Then bu = True
If bu Then
dt = x(i, 5)
x(i, 5) = x(i, 1) 'Total
x(i, 1) = dt 'OrderDate
End If
Next i

Range("G1").Resize(UBound(x), UBound(x, 2)).Value = x
End Sub

snb
08-30-2022, 05:47 AM
Sub M_snb()
With Columns(1).Find("Total")
sn = .Resize(2000, 5)
.Resize(UBound(sn), 5) = Application.Index(sn, [row(1:2000)], Array(5, 2, 3, 4, 1))
End With
End Sub

nilem
08-30-2022, 06:52 AM
Hi Snb,
what if there are more than 60,000 rows in the data?
Glad to see you )

snb
08-30-2022, 07:58 AM
Hi @Nil,

Then I'd ask for a better CSV-file :banghead:
Likewise (has been some time....)