+ Reply to Thread
Results 1 to 3 of 3

Thread: Need macro to find a column and insert it...

  1. #1
    Registered User
    Join Date
    06-15-2011
    Location
    Tennessee, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Post Need macro to find a column and insert it...

    Hi all! I am new to VBA, and I have taken on (what seems to me) a hard task.

    I need a macro that will find the last column in a sheet, then go 3 columns left and copy the data (formulas and all) in that column. Then I need to insert the copied column to the right while retaining data in the columns to the right.

    I know right now I am nowhere near the mark... Actually I just started learning VBA about an hour and a half ago, so be easy on me.
    This is what I have so far:

    Sub FindLastColumn()
        Dim LastColumn As Range
            Set LastColumn = Range("IV10").End(xlToLeft)
    
            With LastColumn
                With .EntireColumn
                    .Copy .Offset(, -3)
                    Selection.Insert Shift:=x1toright
                    .Copy
                    .PasteSpecial xlPasteAll
                End With
            End With
    
        Application.CutCopyMode = False
    End Sub
    Note that I used "IV10". This is just because most of my data starts at row 10.
    Also, I don't know how to do any other paste than Paste Special, so helping me correct this is also great.

    Thanks in advance for all those willing to help!!

    (I can also attach a generic spreadsheet if my explanation is vague)

  2. #2
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Need macro to find a column and insert it...

    hi cdustybk, I have slightly modified your code, you were close:
    Sub FindLastColumn()
        Dim LastColumn As Range
        Set LastColumn = Cells(11, Columns.Count).End(xlToLeft)
        With LastColumn
            With .EntireColumn
                .Copy .Offset(, -3)
                .Insert Shift:=x1toright
            End With
        End With
    End Sub
    Please leave a message after the beep!

  3. #3
    Registered User
    Join Date
    06-15-2011
    Location
    Tennessee, USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Need macro to find a column and insert it...

    Thank you, Mordred for replying so fast. This is almost what I need. However, instead of copying the last column and inserting it, I need the column 3 from the last one to be copied and pasted. However, I may be able to mess with the code and figure it out. VBA is pretty intimidating!

    Thanks for your help though! Rep+1!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0