+ Reply to Thread
Results 1 to 13 of 13

Insert Column after Last Inserted Column

Hybrid View

  1. #1
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Insert Column after Last Inserted Column

    Hi, mariosmk555,

    you should be more precise in what you are asking. In the opening post it was one column (the last one) which should be shifted. Now itīs two columns, and Iīm not so sure about the columns you have used or the range where to insert:
    Sub EF1008505_4()
    'insert two columns before the last two columns of data
    Dim lngIns As Long
    lngIns = Cells(1, Columns.Count).End(xlToLeft).Column - 1
    If lngIns < 3 Then lngIns = 3
    Cells(1, lngIns).Resize(1, 2).EntireColumn.Insert
    End Sub
    Sub EF1008505_5()
    'will start at Column C and add two columns when the workbook isnīt closed in the meantime
    'If you wan to keep the value for the next opening you could write it to a cell on a hidden sheet,
    'use a Name to store it or store the value in a textfile.
    Static lngIns As Long
    If lngIns = 0 Then
      lngIns = 3
    Else
      lngIns = lngIns + 2
    End If
    Cells(1, lngIns).Resize(1, 2).EntireColumn.Insert
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  2. #2
    Registered User
    Join Date
    03-21-2014
    Location
    Russia, Moscow
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: Insert Column after Last Inserted Column

    Hello again you are very helpful.
    I understand the code you wrote above.
    But I think that it can be done simpler but I do not have the time to implement the idea. So let me tell what I am thinking.

    Instead of using the first column as reference which means that we have to store the relative position after closing excel,

    is it possible to give a name on column "E"="SteadyColumn"? Because what I want is to always create two new columns before the "SteadyColumn"
    Doing that if we use as reference the named cell, it is simpler isn't it?

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Insert Column after Last Inserted Column

    Hi, mariosmk555,

    mark the cell with the cursor, goto the NameWindow (where you see the Cell Address), put "SteadyColumn" (without quotes and blanks) and press Enter.

    Sub EF1008505_6()
    Range("SteadyColumn").Resize(1, 2).EntireColumn.Insert
    End Sub
    Stop quoting full posts, please! And if your Excel can convert pictures into Workbooks go ahead with posting pictures (my versions of Excel canīt do that).

    Ciao,
    Holger

  4. #4
    Registered User
    Join Date
    03-21-2014
    Location
    Russia, Moscow
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: Insert Column after Last Inserted Column

    Perfect!
    If you could also answer this question since you solved the problem, you will be extremely helpful.

    How I can copy information from another cell to the newly created columns but by refering to them not by their actual names but as the column which is 1 time left to steady column and 2 times left to steady column?

    This is only what I need: Range("SteadyColumn"-1) ..

    You are a pro mate!!
    Last edited by mariosmk555; 05-04-2014 at 09:18 AM.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Insert Column after Last Inserted Column

    Hi, mariosmk555,

    you should really make up your mind about what you want prior to asking questions and not alter the requirements on each post.

    Sub EF1008505_7()
    With Range("SteadyColumn")
      .Resize(1, 2).EntireColumn.Insert
      .Offset(0, -2).Resize(1, 2).EntireColumn.Value = .Offset(0, -4).Resize(1, 2).EntireColumn.Value
    End With
    End Sub
    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    03-21-2014
    Location
    Russia, Moscow
    MS-Off Ver
    Excel 2013
    Posts
    39

    Re: Insert Column after Last Inserted Column

    Sorry but I don't really know how it works since is my first in the forum.

    Can you please elaborate on the code that you just wrote?

    Range("A1:B1").Select
    Selection.Copy
    I want to paste the copied information from cells A1 and B1 on the two new columns. How do I do that using your code?
    Thanks again, and this is my last question on this post following your guidance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Add a checkbox to column whenever a new row is inserted
    By Phillips Contracting in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2014, 01:44 PM
  2. Copy column sub-headings to inserted column via formula
    By Geppstar in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-13-2013, 05:36 PM
  3. Sum of columns to right - update when new column inserted
    By miro2021 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-21-2013, 11:00 AM
  4. Insert column and fill column upto where data is in previous column
    By aka189 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2012, 06:07 AM
  5. AUTO INSERT A COLUMN'S FORMULA IN MANUALLY INSERTED ROWS
    By JLah in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-20-2006, 11:15 AM

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.6.0 RC 1