Results 1 to 3 of 3

Data and number manipulation

Threaded View

Mwhite Data and number manipulation 06-13-2007, 01:05 PM
Guest I just noticed that you said... 06-13-2007, 04:15 PM
markgroves Re: Data and number... 05-15-2015, 06:41 AM
  1. #2
    mpeplow
    Guest
    I just noticed that you said the number is a date. If possible, if you could attached a spreadsheet for testing, it would help.
    possible alteration to
    Dim First_Num As Integer
    Dim Second_Num As Integer
    'Change the above to the below
    Dim First_Num As Date
    Dim Second_Num Date
    Could work if you experince problems, but I haven't tested it.


    Very little testing was done with this code on a spreadsheat created using your example.

    I think it will work just fine. Try this.

    NOTE:This code assumes the following.
    All of you numbers are in column A
    Colum A contains no blank cells before the end of the sheet
    You have a header on your worksheet


    Option Explicit
    Sub Complete_Missing_Data()
    
    Dim First_Num As Integer
    Dim Second_Num As Integer
    Dim i As Integer
    
    Dim FinalRow As Long
        FinalRow = Range("A65536").End(xlUp).Row
        
    For i = FinalRow To 2 Step -1
        First_Num = Range("A" & i).Value
        Second_Num = Range("A" & i - 1).Value
        
        If First_Num - 1 <> Second_Num Then
            Rows(i).Insert
            Range("A" & i).Value = First_Num - 1
            FinalRow = FinalRow + 1
            i = i + 1
        End If
    Next i
    
    End Sub
    to make this work. open your sheet click on tools, option, visual basic editor. right click on thisworkbook and select insert modual. Past the code in there. press F5 to run the code on the sheet that you opened.

    if you want to run this on a workbook with multiple sheets, use the following.
    Option Explicit
    Sub Complete_Missing_Data()
    
    Dim First_Num As Integer
    Dim Second_Num As Integer
    Dim i As Integer
    Dim WrkSht As Worksheet
    
    For Each WrkSht In Worksheets
    WrkSht.Select
    Dim FinalRow As Long
        FinalRow = Range("A65536").End(xlUp).Row
        
    For i = FinalRow To 2 Step -1
        First_Num = Range("A" & i).Value
        Second_Num = Range("A" & i - 1).Value
        
        If First_Num - 1 = Second_Num Then
            'Do nothing
        End If
        If First_Num - 1 <> Second_Num Then
            Rows(i).Insert
            Range("A" & i).Value = First_Num - 1
            FinalRow = FinalRow + 1
            i = i + 1
        End If
    Next i
    Next WrkSht
    
    End Sub
    IMPORTANT NOTE: THIS CODE MIGHT ENCOUNTER PROBLEMS DEPENDING ON WHAT IS CONTAINED IN YOU HEADER. THIS WAS TESTED ON A SHEET WITH A BLANK LINE ON ROW 1.
    Last edited by mpeplow; 06-13-2007 at 04:42 PM.

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