Help with code

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi can someone help to turn it into to an array, I have tried to do an array but got nowhere, if not maybe help with tidying it up.
Thanks

Code:
    With ActiveSheet.UsedRange
        Set c = .Find("Ref-Designator", LookIn:=xlValues)
    ActiveSheet.Range(c.Address).EntireColumn.Cut Destination:=Range("AA:AA")
        Set c = .Find("X Offset", LookIn:=xlValues)
    Application.ScreenUpdating = False
    ActiveSheet.Range(c.Address).EntireColumn.Cut Destination:=Range("AB:AB")
        Set c = .Find("Y Offset", LookIn:=xlValues)
    Application.ScreenUpdating = False
    ActiveSheet.Range(c.Address).EntireColumn.Cut Destination:=Range("AC:AC")
        Set c = .Find("Angle", LookIn:=xlValues)
    Application.ScreenUpdating = False
    ActiveSheet.Range(c.Address).EntireColumn.Cut Destination:=Range("AD:AD")
    End With
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
One suggestion, try replacing all of your code with:
Code:
Dim x       As Long
    Dim var     As Variant
    Dim temp    As Variant
    Dim rng     As Range
    
    With ActiveSheet
        
        For Each var In Array("Ref-Designator|AA1", "X Offset|AB1", "Y Offset|AC1", "Angle|AD1")
            On Error Resume Next
                Set rng = .Cells.find(what:=Split(var, "|")(0), LookIn:=xlValues)
                If Not rng Is Nothing Then
                    x = .Cells(.Rows.Count, rng.Column).End(xlUp).row
                    .Cells(1, rng.Column).Resize(x).Cut .Cells(1, Split(var, "|")(1)).Resize(x).Paste
                    Application.CutCopyMode = False
                    Set rng = Nothing
                End If
            On Error GoTo 0
        Next var
    End With
 
Last edited:
Upvote 0
Hi Jack, your code doesn't do anything, All I want to do is find the headers and move the entire column.
 
Last edited:
Upvote 0
This works for me:
Code:
Sub Macro1()

    Dim x       As Long
    Dim var     As Variant
    Dim temp    As Variant
    Dim rng     As Range
    Dim arr()   As Variant
    
    With ActiveSheet
        
        For Each var In Array("Ref-Designator|AA", "X Offset|AB", "Y Offset|AC", "Angle|AD")
            On Error Resume Next
                Set rng = .Cells.find(what:=Split(var, "|")(0), LookIn:=xlValues)
                If Not rng Is Nothing Then
                    x = .Cells(.Rows.Count, rng.Column).End(xlUp).row
                    With .Cells(1, rng.Column).Resize(x)
                        arr = .Value
                        .ClearContents
                    End With
                    .Cells(1, Split(var, "|")(1)).Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
                    Erase arr
                    Set rng = Nothing
                End If
            On Error GoTo 0
        Next var
    End With
        
End Sub
 
Last edited:
Upvote 0
This works perfectly, Thank you it's much appreciated
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,673
Members
449,463
Latest member
Jojomen56

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