+ Reply to Thread
Results 1 to 4 of 4

Inserting number of rows based on a count of data

Hybrid View

  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    13

    Inserting number of rows based on a count of data

    Hi,

    I have a list of data in column A that changes length. I'm looking for a macro that can insert columns from column O based on twice the count of data in column A.

    eg. if there are 5 entries in Column A, I'd like to insert 10 columns from O. I have the macro to insert columns but it needs an exact number.

    Columns("O:O").Select
        Range(Selection, Selection.Columns(No of columns)).EntireColumn.Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Any help would be great.

    Thanks.
    Last edited by Cutter; 08-15-2012 at 11:23 AM. Reason: Added code tags

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Inserting number of rows based on a count of data

    Sub Insert_Columns()
        Dim num As String
        num = InputBox("How many columns do you want to insert?")
        If num <> "" Then
            If num > 0 Then ActiveCell.Offset(0, 1).Resize(1, num).EntireColumn.Insert
        End If
    End Sub

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Inserting number of rows based on a count of data

    Hi patel,

    That's a great code and will be useful. But for the current file, I'm looking for it to count the number of cells with data and insert twice the number of columns. I'm looking to have as few manual inputs as possible.

    Thanks.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,333

    Re: Inserting number of rows based on a count of data

    Hi Ranelagh,

    It looks like you need some code to count the number of rows in column A.

    I use the following to do that
    Dim LastRowA as Double
    LastRowA = Cells(Rows.Count,"A").End(xlUp).Row
    Then you might be able to do this in your code.
    Range(Selection, Selection.Columns(LastRowA * 2)).EntireColumn.Select
    Hope that helps.

    Look at http://answers.microsoft.com/en-us/o...c-f38bb66afcaa or search for Rows.Count and LastRow on the net for more examples.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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