Results 1 to 7 of 7

Thread: Vba to move columns with certain headers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    2
    Location
    Quote Originally Posted by bayern21 View Post
    Hi,
    I have a similiar issue and can't get my Macro to work...

    Right now I have a column called "057 - Interest Margin" as a header (row 1) in column AM. I want VBA to search for that value and then cut the entire column and move it to column S. If it can't find the column "057 - Interest Margin" VBA is supposed to insert a new column (column S) called "057 - Interest Margin".

    Thanks
    Stefan
    so what I have so far is the following:

    For Each rng In Range("A1:BZ1")
    If rng.Value = "057 - Interest Margin" Then
    rng.EntireColumn.Cut
    Sheets("Sheet1").Select
    Columns("S:S").Select
    Selection.Insert Shift:=xlToRight
    End If
    Next rng

    What I am missing right now is that a new column and a specific header is added in case "057 - Interest Margin" cannot be found.

    I came up with this but it screws up everything because it inserts the column 18 times????


    For Each Rng In Range("A1:BZ1")
    If Rng.Value = "057 - Interest Margin" Then
    Rng.EntireColumn.Cut
    Sheets("Sheet1").Select
    Columns("S:S").Select
    Selection.Insert Shift:=xlToRight
    Else:
    Columns("S:S").Select
    Selection.Insert Shift:=xlToRight
    Range("S1").Select
    ActiveCell.FormulaR1C1 = "057 - Interest Margin"
    Range("S2").Select
    End If
    Next Rng
    Last edited by bayern21; 11-15-2016 at 03:23 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •