Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Remove all rows except ones containing selected date

Posted on 2012-03-12
1
199 Views
Last Modified: 2012-07-17
Good Morning Experts;

I have an Excel Workbook that performs a series of tasks before creating a CSV file for export into Timberline.

My boss has asked that the control worksheet now remove all rows from sheet Labor_Totals_Temp except for ones containing a user prompted date. I've attached a copy of the spreadsheet in its working state. Stage 4 is the button that should trigger the search and removal of unneeded entries in sheet Labor_Totals_Temp.

Simply put the following should occur.

User clicks on Stage 4 on sheet "Controls"
User is prompted for a date in format mm/dd/yyyy
Macro goes to sheet "Labor_Totals_Temp" and deletes all rows that do NOT have the prompted date.


Regards,
Brian
Z-Master-Daily-Converter-2007---.xlsm
0
Comment
Question by:RedstoneIT
1 Comment
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 37714007
Public Sub DeleteNonDateRows()
    Dim dtDate As Date
    Dim strDate As String
    Dim wks As Worksheet
    Dim rng As Range
    Dim rngCell As Range
    Dim rngDelete As Range
    
    strDate = InputBox("Enter date (mm/dd/yyyy)", "Date prompt", Date)
    If IsDate(strDate) Then
        dtDate = strDate
    Else
        MsgBox "Invalid date entered.  Please try again", vbCritical
        Exit Sub
    End If
    Set wks = Worksheets("Labor_Totals_Temp")
    Set rng = wks.Range("B2")
    Set rng = wks.Range(rng, rng.End(xlDown))
    For Each rngCell In rng
        If rngCell.Value <> dtDate Then
            If rngDelete Is Nothing Then
                Set rngDelete = rngCell.EntireRow
            Else
                Set rngDelete = Union(rngDelete, rngCell.EntireRow)
            End If
        End If
    Next
    If rngDelete Is Nothing Then
    Else
        Application.ScreenUpdating = False
        'Debug.Print rngDelete.Address
        rngDelete.Delete
        Application.ScreenUpdating = True
    End If
End Sub

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question