Results 1 to 8 of 8

Thread: VBA To Insert Specific Column Before Every Existing Columns

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0

    VBA To Insert Specific Column Before Every Existing Columns

    hi i have many columns up to 500 and i want to insert one column that is spesified time before every colunmns with vb the column is as below 00:00 00:30 . . . . . 23:00 23:30 00:00

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by CORAL View Post
    hi i have many columns up to 500 and i want to insert one column that is spesified time before every colunmns with vb the column is as below 00:00 00:30 . . . . . 23:00 23:30 00:00
    Does this macro do what you want?
    Code:
    Sub InsertRowBefore()
         Dim X As Long, Col As String
         Col = Application.InputBox("Enter time to insert at...", Type:=2)
         For X = 100 To 1 Step -1
             If Cells(1, X).Text = Col Then Columns(X).Insert
         Next
     End Sub

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0
    maybe i cant explain well and possible that i cant use the code properly please help me i want to insert one spesified column before every column(up to 400)
    this column is
    00:00
    00:30
    01:00
    01:30
    02:00
    02:30
    03:00
    03:30
    04:00
    04:30
    05:00
    05:30
    06:00
    06:30
    07:00
    07:30
    08:00
    08:30
    09:00
    09:30
    10:00
    10:30
    11:00
    11:30
    12:00
    12:30
    13:00
    13:30
    14:00
    14:30
    15:00
    15:30
    16:00
    16:30
    17:00
    17:30
    18:00
    18:30
    19:00
    19:30
    20:00
    20:30
    21:00
    21:30
    22:00
    22:30
    23:00
    23:30
    00:00

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    I am apparently having trouble figuring out your layout and what you want to do with it. Can you create a sample workbook where on Sheet1 you show existing data similar to what you actually have as real data and then on Sheet2 you copy that exact data and then insert the columns you want inserted and then attach a copy of that workbook to your response so that we can see exactly what you are trying to describe to us?

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0
    i shared the excel file here a - Download - 4shared - marjan mashayekhpour
    with best regard

  6. #6
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0
    i cant attach and i dont know why

  7. #7
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    If the file size is more than limit, try saving it to a file share site, and post the link here.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  8. #8
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    You can't add columns to a worksheet: it always contains 16384 columns.
    You can move data in the worksheet though:

    Code:
    Sub M_snb()
       sheets("sheet1").usedrange.cut sheets("sheet1").cells(1,2)
    End sub

Similar Threads

  1. Replies: 6
    Last Post: 07-26-2013, 11:42 AM
  2. Replies: 8
    Last Post: 07-01-2013, 03:52 PM
  3. Insert Or Delete Columns Based On User Input
    By HDMI in forum Excel Help
    Replies: 4
    Last Post: 06-21-2013, 03:00 AM
  4. Macro To Insert Columns In Excel
    By jac3130 in forum Excel Help
    Replies: 2
    Last Post: 05-17-2013, 07:49 AM
  5. Replies: 9
    Last Post: 09-09-2011, 02:30 AM

Posting Permissions

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