Results 1 to 9 of 9

Wont select the row intended

Threaded View

  1. #1
    Registered User
    Join Date
    09-08-2009
    Location
    Glasgow
    MS-Off Ver
    Excel 2003 SP3
    Posts
    45

    Question Wont select the row intended

    Hey there,

    I have created a macro to delete any row which has a date older than the date specified by the user. However for some odd reason, when the macro finds a row which has an older date, it doesnt select that date and ends up selecting a completely different row and deletes that.

    My macro code is shown below and I have attached my spreadsheet. If anyone has a clue as to why its selecting the wrong row then that would be great as I am quite honestly baffled!

    Sub Remove_Old_Data_New()
    
    Dim dateDim As Date, strDate As String, foundRange As Range, rangeDel As Range, i As Long, lastRow As Long
    Dim confirmDelete As String
    
    Dim convertedDate As Long
    Dim convertedFoundDate As Long
    
    dateDim = Application.InputBox(Prompt:="Please enter the date you wish to filter from: ", _
              Title:="Date Filter", Default:=Format(Date, "DD/MM/YYYY"), Type:=1)
    If dateDim Then
        strDate = Format(dateDim, "DD/MM/YYYY")
    Else
        MsgBox "Action Cancelled"
    End If
    
    MsgBox "The date entered is: " & dateDim, vbInformation, "Remove Old Data"
    
    convertedDate = CDate(strDate)
    
    MsgBox convertedDate
    
    ActiveSheet.Select
    
    convertedFoundDate = CDate(Cells(5342, 14).Value)
    
    
    With ActiveSheet
        For i = 2 To .UsedRange.Rows.Count
            convertedFoundDate = CDate(Cells(i, 14).Value)
            If convertedFoundDate <= convertedDate Then
                .Cells(i).EntireRow.Select
                MsgBox convertedFoundDate
                MsgBox i
                .Cells(i).EntireRow.Delete
            End If
        Next i
    End With
    
    End Sub
    For some odd reason I keep getting a database error when I try to upload my spreadsheet but I'll try again once I post this thread.

    Thanks,

    Jag
    Last edited by therealjag; 02-23-2010 at 11:42 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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