LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Macro to Recognize Dates

You should be able to use the vba IsDate function : ? isdate(" 01/10/1901 ")
If that doesn't work on your cell then there is, maybe, some extra
characters preventing the convertion.
- by "doesn't work", do you mean the code breaks on an error or just
continue to process witout selecting that row.
- select one of these 'non-working' cell, say A10 and do
=len(A10) to determine length (does it match the length of the text
you see)
= len(trim(clear(A10))) any difference from the above length?
= A10+1 add 1 day to the date ... what's the result?
= "" & A10 & "<" does this have extra spaces between < and the
date?

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"JoeS" wrote:

Still not recognizing the dates. The text format doesn't seem to be picking
up the text either.

Is there a way to simply say if activecell is a date in ##/##/#### format,
delete the entire row?

-- Joe S


"sebastienm" wrote:

1. Check the online help for the Select Case, you'll see that you can group
muliple case with:
Select Case ActiveCell
Case "Print", "Page", "Users", "Status"
.....
2. Any way, try the follwoing:

Sub test()
Dim rg As Range, rgDelete As Range
Dim TextValues As String
Dim IsToBeDeleted As Boolean, IsInTextValues As Boolean, IsADate As Boolean

Set rg = Range("A1")
TextValues = "Print,Page,Users,Status"


On Error Resume Next ' to prevent error when converting date
TextValues = "," & TextValues & ","

Do Until rg = ""
rg.Select
'check for text values
IsInTextValues = TextValues Like ("*," & rg.Text & ",*")
'check for a date
IsADate = (CDate(rg.Text) DateValue("01/10/1901"))
If Err < 0 Then Err.Clear
'Is to be deleted
IsToBeDeleted = IsInTextValues Or IsADate
If IsToBeDeleted Then
If rgDelete Is Nothing Then 'no range in it yet
Set rgDelete = rg
Else 'just add to it
Set rgDelete = Application.Union(rg, rgDelete)
End If
End If
'next cell
IsADate = False
IsInTextValues = False
Set rg = rg.Offset(1, 0)
Loop

'Delete at the end only
If Not rg Is Nothing Then
rg.EntireRow.Delete 'rgDelete.EntireRow.Select
End If
End Sub

I hope this helps
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sumif Formula - Won't Recognize Dates Dwolko Excel Discussion (Misc queries) 3 August 19th 08 10:21 PM
Modify A Macro To Recognize Case Sensitive carl Excel Worksheet Functions 3 April 2nd 08 10:45 PM
Problem to recognize macro Stefan New Users to Excel 2 June 4th 07 07:33 PM
Problem to recognize macro Stefan Excel Discussion (Misc queries) 2 June 4th 07 02:00 AM
Having a macro recognize when an option button has been selected Linking to specific cells in pivot table Excel Programming 3 August 26th 05 05:21 PM


All times are GMT +1. The time now is 09:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"