+ Reply to Thread
Results 1 to 2 of 2

Insert columns until a certain number has been reached

  1. #1
    Registered User
    Join Date
    08-18-2005
    Posts
    34

    Insert columns until a certain number has been reached

    Hi all,

    I need help with inserting a variable number of columns. Heres the details:

    In one sheet I have 52 columns (this will always change) of data and in another I have 50 (again this will change). In the sheet with 50 I would like to insert X number of columns so both sheets have the same number. (52)

    I cannot just copy and paste as formulas I have written previously will be overwritten.

    I am fairly new to writing tihs type of code but heres what I have:

    Dim RawDataColCount As Integer
    Sheets("Raw Data").Select
    RawDataColCount = Cells.SpecialCells(xlCellTypeLastCell).Column

    Sheets("Data").Select
    Dim DataColCount As Integer
    DataColCount = Columns("B:AY").Count

    If RawDataColCount > DataColCount Then
    Sheets("Data").Select
    Range("B:B").Select
    Selection.Insert Shift:=xlToRight
    Do Until DataColCount = RawDataColCount
    DataColCount = DataColCount + 1
    Loop

    End If

  2. #2
    Ardus Petus
    Guest

    Re: Insert columns until a certain number has been reached

    If RawDatacolcount > Datacolcount Then
    Range("B:B").Resize(, RawDatacolcount - Datacolcount).Select
    Selection.Insert Shift:=xlToRight
    End If

    This will insert n columns at a time

    HTH
    --
    AP

    "moglione1" <[email protected]> a écrit
    dans le message de
    news:[email protected]...
    >
    > Hi all,
    >
    > I need help with inserting a variable number of columns. Heres the
    > details:
    >
    > In one sheet I have 52 columns (this will always change) of data and in
    > another I have 50 (again this will change). In the sheet with 50 I would
    > like to insert X number of columns so both sheets have the same number.
    > (52)
    >
    > I cannot just copy and paste as formulas I have written previously will
    > be overwritten.
    >
    > I am fairly new to writing tihs type of code but heres what I have:
    >
    > Dim RawDataColCount As Integer
    > Sheets("Raw Data").Select
    > RawDataColCount = Cells.SpecialCells(xlCellTypeLastCell).Column
    >
    > Sheets("Data").Select
    > Dim DataColCount As Integer
    > DataColCount = Columns("B:AY").Count
    >
    > If RawDataColCount > DataColCount Then
    > Sheets("Data").Select
    > Range("B:B").Select
    > Selection.Insert Shift:=xlToRight
    > Do Until DataColCount = RawDataColCount
    > DataColCount = DataColCount + 1
    > Loop
    >
    > End If
    >
    >
    > --
    > moglione1
    > ------------------------------------------------------------------------
    > moglione1's Profile:

    http://www.excelforum.com/member.php...o&userid=26414
    > View this thread: http://www.excelforum.com/showthread...hreadid=530422
    >




+ 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