+ Reply to Thread
Results 1 to 3 of 3

simple deletion won't work for me

  1. #1
    Registered User
    Join Date
    01-29-2006
    Posts
    3

    simple deletion won't work for me

    Hi!
    I wish to have an Excel sheet which simply looks at the date and if that date or past, delete a range. This should be so simple but I can't get it to work.
    Here's what I have:

    Sub deleterange()
    '
    'dim datadate
    datadate = Range("b3").Value
    ' If datadate > 38747 Then
    Range("C5:D11").Select
    selection.Clear
    MsgBox "datadate is " & datadate

    End Sub

    With the above, the variable "datadate" comes into the message box as 38747 so the logic or syntax of my If is off. And after a bunch of time, the various "Help" files have not.
    Thanks for your time and fix
    John

  2. #2
    Dave Peterson
    Guest

    Re: simple deletion won't work for me

    How about:

    Sub deleterange()
    '
    dim datadate as date
    datadate = Range("b3").Value
    If datadate > dateserial(2006,1,30) Then
    Range("C5:D11").Clear '.clearcontents????
    end if
    MsgBox "datadate is " & datadate

    End Sub

    But your code worked ok (after I uncommented a couple of lines and added an End
    if):

    Option Explicit
    Sub deleterange()
    '
    Dim datadate
    datadate = Range("b3").Value
    If datadate > 38747 Then
    Range("C5:D11").Select
    Selection.Clear
    End If
    MsgBox "datadate is " & datadate

    End Sub

    (I just find reading 38747 much more difficult than dateserial(2006,1,30).)

    jgriffs wrote:
    >
    > Hi!
    > I wish to have an Excel sheet which simply looks at the date and if
    > that date or past, delete a range. This should be so simple but I can't
    > get it to work.
    > Here's what I have:
    >
    > Sub deleterange()
    > '
    > 'dim datadate
    > datadate = Range("b3").Value
    > ' If datadate > 38747 Then
    > Range("C5:D11").Select
    > selection.Clear
    > MsgBox "datadate is " & datadate
    >
    > End Sub
    >
    > With the above, the variable "datadate" comes into the message box as
    > 38747 so the logic or syntax of my If is off. And after a bunch of
    > time, the various "Help" files have not.
    > Thanks for your time and fix
    > John
    >
    > --
    > jgriffs
    > ------------------------------------------------------------------------
    > jgriffs's Profile: http://www.excelforum.com/member.php...o&userid=30947
    > View this thread: http://www.excelforum.com/showthread...hreadid=506184


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    01-29-2006
    Posts
    3

    Thumbs up Thanks!

    I was hoping it was something simple (the single quotes being "rem"ed out). I also eliminated the idea of looking up the date from a cell and just used "Date".
    Thanks for getting me on track. Obviously I'm just getting started learning this VB stuff. Lotus macros - I'm a wiz and the conversion to VB ain't so simple. In fact, the only conversion is really the "logic" of programing.
    Thanks again

+ 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