+ Reply to Thread
Results 1 to 4 of 4

Insert Column when a sequential isn't found

Hybrid View

reggie1000 Insert Column when a... 05-13-2013, 11:45 AM
AB33 Re: Insert Column when a... 05-13-2013, 12:32 PM
reggie1000 Re: Insert Column when a... 05-14-2013, 11:28 AM
AB33 Re: Insert Column when a... 05-14-2013, 11:39 AM
  1. #1
    Forum Contributor
    Join Date
    11-23-2007
    Location
    Suffolk, UK
    Posts
    298

    Insert Column when a sequential isn't found

    Hello,

    I have a problem, where i have a row of numbers and data underneath that are imported in they sit in row A and run to column 20, these numbers are sequential 1,2,3,4 etc, but there are sometimes that certain numbers are missing, what i need to do is to insert the missing number and column when they are missing.The missing numbers/column may be random but it always will finish up in the correct order when imported.

    Hopefully it should be to much of a problem, i've attached a sample file to explain the problem better.

    thanks reg
    Attached Files Attached Files
    Last edited by reggie1000; 05-14-2013 at 11:28 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert Column when a sequential isn't found

    Try this code

    Sub test()
        Dim i As Long, x, LC&
        On Error Resume Next
        Application.ScreenUpdating = 0
     With ActiveSheet
        LC = .Cells.Find("*", , , , xlByColumns, xlPrevious).Column
    
        For i = LC To 2 Step -1
            x = .Cells(1, i) - .Cells(1, i - 1)
            If x > 1 Then
                .Columns(i).Insert
                .Cells(1, i - 1).AutoFill .Cells(1, i - 1).Resize(, x), 2
            End If
        Next
     End With
     Application.ScreenUpdating = True
    End Sub

  3. #3
    Forum Contributor
    Join Date
    11-23-2007
    Location
    Suffolk, UK
    Posts
    298

    Re: Insert Column when a sequential isn't found

    Thanks AB33, its like a charm,

    Many thanks Reg

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert Column when a sequential isn't found

    Reg,
    You are Welcome!

+ 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