SteveOranjin
Board Regular
- Joined
- Dec 18, 2017
- Messages
- 170
Hello,
I have the below formula which was working quite nicely earlier. I brought it from one sheet and pasted it into a data sheet that I do work with. This is meant to help me work through data by organizing the columns of data. I want to create other VBA Macros that will insert formulas next to these columns based off of their header.
I'm not quite sure what the heck this thing is doing. I think it is only reorganizing columns I and J or something.
What I was trying to get it to do is
Reorder all columns (and associated data below the headers). based off of the order you'll see there. I'd like to see this work to regardless of whether or not all of the columns are actually present. AND if there are any other columns that do not conform to the headers in the code, then I'd like those columns to just be slapped on at the end. Any particular order for those is find as long as the integrity of the data is maintained.
Please help!
Thanks so much!
Steve
I have the below formula which was working quite nicely earlier. I brought it from one sheet and pasted it into a data sheet that I do work with. This is meant to help me work through data by organizing the columns of data. I want to create other VBA Macros that will insert formulas next to these columns based off of their header.
I'm not quite sure what the heck this thing is doing. I think it is only reorganizing columns I and J or something.
What I was trying to get it to do is
Reorder all columns (and associated data below the headers). based off of the order you'll see there. I'd like to see this work to regardless of whether or not all of the columns are actually present. AND if there are any other columns that do not conform to the headers in the code, then I'd like those columns to just be slapped on at the end. Any particular order for those is find as long as the integrity of the data is maintained.
Please help!
Thanks so much!
Steve
Code:
Sub Reoder_Columns_Based_Off_Of_Header()Dim rng As Range
Dim i As Integer
Dim J As Integer
Dim Temp
Dim nams As Variant
Dim F
Dim Dex As Integer
nams = Array("Brandname", "Brandcode", "Sku", "UPC", "productName", "Product Name", "msrp", "MSRP", "mapprice", "dnprice", "Category", "mCategory", "mSubCategory", "Model", "mFinish", "Finish", "finish", "Descirption", "Marketing Copy", "CollectionName", "Length", "Width", "Height", "Weight", "dimensionstring", "ship length", "ship width", "ship height", "shipWeight", "shipstring", "Bullet1", "Bullet2", "Bullet3", "Bullet4", "Bullet5", "speclink", "installlink", "imageName", "Imagelink", "VideoLink1", "Oversized")
Set rng = Range("A1").CurrentRegion
For i = 1 To rng.Columns.Count
For J = i To rng.Columns.Count
For F = 0 To UBound(nams)
If nams(F) = rng(J) Then Dex = F: Exit For
Next F
If F < i Then
Temp = rng.Columns(i).Value
rng(i).Resize(rng.Rows.Count) = rng.Columns(J).Value
rng(J).Resize(rng.Rows.Count) = Temp
End If
Next J
Next i
End Sub