+ Reply to Thread
Results 1 to 9 of 9

VBA Help needed -- compile error: object required

  1. #1
    alexandraVBAgirl
    Guest

    VBA Help needed -- compile error: object required

    This code always gives me the error above. I have no idea what's wrong with
    this
    The point is to go through a list of dates and if they are less than say
    1/1/2005 (my start date entered in the spreadsheet) change them to 0 and
    keep others as is. But this doesn't seem to work at all. Could anyone pls
    help me? Thanks

    Sub click()

    Dim counter As Integer
    Dim curCell As Date
    Dim startDate As Date
    Dim endDate As Date


    Range("e1").Value = startDate

    For counter = 1 To 20
    Set curCell = Worksheets("sheet1").Cells(counter, 3)
    If curCell.Value < startDate.Value Then curCell.Value = 0
    Next counter
    End If

    End Sub

  2. #2
    Bob Phillips
    Guest

    Re: VBA Help needed -- compile error: object required

    This compiled for me

    Sub click()

    Dim counter As Integer
    Dim curCell As Date
    Dim startDate As Date
    Dim endDate As Date


    Range("e1").Value = startDate

    For counter = 1 To 20
    curCell = Worksheets("sheet1").Cells(counter, 3)
    If curCell < startDate Then curCell = 0
    Next counter

    End Sub


    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "alexandraVBAgirl" <[email protected]> wrote in
    message news:[email protected]...
    > This code always gives me the error above. I have no idea what's wrong

    with
    > this
    > The point is to go through a list of dates and if they are less than say
    > 1/1/2005 (my start date entered in the spreadsheet) change them to 0 and
    > keep others as is. But this doesn't seem to work at all. Could anyone pls
    > help me? Thanks
    >
    > Sub click()
    >
    > Dim counter As Integer
    > Dim curCell As Date
    > Dim startDate As Date
    > Dim endDate As Date
    >
    >
    > Range("e1").Value = startDate
    >
    > For counter = 1 To 20
    > Set curCell = Worksheets("sheet1").Cells(counter, 3)
    > If curCell.Value < startDate.Value Then curCell.Value = 0
    > Next counter
    > End If
    >
    > End Sub




  3. #3
    alexandraVBAgirl
    Guest

    Re: VBA Help needed -- compile error: object required

    Thanks, Bob, that seems to eliminate the error message. However, the
    worksheet's startdate entered as 1/1/2005 initially turns to 12:00:00 AM as i
    execute the macro. I got that before as well. Why does that happen?

    my worksheet view

    1/1/2004 start date 12:00:00 AM
    1/2/2004 end date 2/2/2006
    1/1/2005
    1/2/2005
    1/3/2005
    1/4/2005
    1/5/2005
    1/6/2005
    1/7/2005
    1/8/2005
    1/9/2005
    1/10/2005
    1/11/2005
    1/12/2005
    1/13/2005
    1/14/2005
    1/15/2005
    1/16/2005
    1/17/2005
    1/18/2005

    Thanks.


    "Bob Phillips" wrote:

    > This compiled for me
    >
    > Sub click()
    >
    > Dim counter As Integer
    > Dim curCell As Date
    > Dim startDate As Date
    > Dim endDate As Date
    >
    >
    > Range("e1").Value = startDate
    >
    > For counter = 1 To 20
    > curCell = Worksheets("sheet1").Cells(counter, 3)
    > If curCell < startDate Then curCell = 0
    > Next counter
    >
    > End Sub
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "alexandraVBAgirl" <[email protected]> wrote in
    > message news:[email protected]...
    > > This code always gives me the error above. I have no idea what's wrong

    > with
    > > this
    > > The point is to go through a list of dates and if they are less than say
    > > 1/1/2005 (my start date entered in the spreadsheet) change them to 0 and
    > > keep others as is. But this doesn't seem to work at all. Could anyone pls
    > > help me? Thanks
    > >
    > > Sub click()
    > >
    > > Dim counter As Integer
    > > Dim curCell As Date
    > > Dim startDate As Date
    > > Dim endDate As Date
    > >
    > >
    > > Range("e1").Value = startDate
    > >
    > > For counter = 1 To 20
    > > Set curCell = Worksheets("sheet1").Cells(counter, 3)
    > > If curCell.Value < startDate.Value Then curCell.Value = 0
    > > Next counter
    > > End If
    > >
    > > End Sub

    >
    >
    >


  4. #4
    alexandraVBAgirl
    Guest

    Re: VBA Help needed -- compile error: object required

    but if i change the code slightly the start date and end date stay as entered
    on the worksheet, however, nothing turns to zero.

    Sub click()

    Dim counter As Integer
    Dim curCell As Date
    Dim startDate As Date
    Dim endDate As Date

    startDate = Range("e1").Value
    endDate = Range("e2").Value

    'Range("e1").Value = startDate
    'Range("e2").Value = endDate

    For counter = 1 To 20
    curCell = Worksheets("sheet1").Cells(counter, 3)
    If curCell < startDate Then curCell = 0

    Next counter

    End Sub

    worksheet:

    1/1/2004 start date 1/1/2006
    1/2/2004 end date 2/2/2006
    1/1/2005
    1/2/2005
    1/3/2005
    1/4/2005
    1/5/2005
    1/6/2005
    1/7/2005
    1/8/2005
    1/9/2005
    1/10/2005
    1/11/2005
    1/12/2005
    1/13/2005
    1/14/2005
    1/15/2005
    1/16/2005
    1/17/2005
    1/18/2005

    "alexandraVBAgirl" wrote:

    > Thanks, Bob, that seems to eliminate the error message. However, the
    > worksheet's startdate entered as 1/1/2005 initially turns to 12:00:00 AM as i
    > execute the macro. I got that before as well. Why does that happen?
    >
    > my worksheet view
    >
    > 1/1/2004 start date 12:00:00 AM
    > 1/2/2004 end date 2/2/2006
    > 1/1/2005
    > 1/2/2005
    > 1/3/2005
    > 1/4/2005
    > 1/5/2005
    > 1/6/2005
    > 1/7/2005
    > 1/8/2005
    > 1/9/2005
    > 1/10/2005
    > 1/11/2005
    > 1/12/2005
    > 1/13/2005
    > 1/14/2005
    > 1/15/2005
    > 1/16/2005
    > 1/17/2005
    > 1/18/2005
    >
    > Thanks.
    >
    >
    > "Bob Phillips" wrote:
    >
    > > This compiled for me
    > >
    > > Sub click()
    > >
    > > Dim counter As Integer
    > > Dim curCell As Date
    > > Dim startDate As Date
    > > Dim endDate As Date
    > >
    > >
    > > Range("e1").Value = startDate
    > >
    > > For counter = 1 To 20
    > > curCell = Worksheets("sheet1").Cells(counter, 3)
    > > If curCell < startDate Then curCell = 0
    > > Next counter
    > >
    > > End Sub
    > >
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "alexandraVBAgirl" <[email protected]> wrote in
    > > message news:[email protected]...
    > > > This code always gives me the error above. I have no idea what's wrong

    > > with
    > > > this
    > > > The point is to go through a list of dates and if they are less than say
    > > > 1/1/2005 (my start date entered in the spreadsheet) change them to 0 and
    > > > keep others as is. But this doesn't seem to work at all. Could anyone pls
    > > > help me? Thanks
    > > >
    > > > Sub click()
    > > >
    > > > Dim counter As Integer
    > > > Dim curCell As Date
    > > > Dim startDate As Date
    > > > Dim endDate As Date
    > > >
    > > >
    > > > Range("e1").Value = startDate
    > > >
    > > > For counter = 1 To 20
    > > > Set curCell = Worksheets("sheet1").Cells(counter, 3)
    > > > If curCell.Value < startDate.Value Then curCell.Value = 0
    > > > Next counter
    > > > End If
    > > >
    > > > End Sub

    > >
    > >
    > >


  5. #5
    alexandraVBAgirl
    Guest

    Re: VBA Help needed -- compile error: object required

    but if i change the code slightly the start date and end date stay as entered
    on the worksheet, however, nothing turns to zero.

    Sub click()

    Dim counter As Integer
    Dim curCell As Date
    Dim startDate As Date
    Dim endDate As Date

    startDate = Range("e1").Value
    endDate = Range("e2").Value

    'Range("e1").Value = startDate
    'Range("e2").Value = endDate

    For counter = 1 To 20
    curCell = Worksheets("sheet1").Cells(counter, 3)
    If curCell < startDate Then curCell = 0

    Next counter

    End Sub

    worksheet:

    1/1/2004 start date 1/1/2006
    1/2/2004 end date 2/2/2006
    1/1/2005
    1/2/2005
    1/3/2005
    1/4/2005
    1/5/2005
    1/6/2005
    1/7/2005
    1/8/2005
    1/9/2005
    1/10/2005
    1/11/2005
    1/12/2005
    1/13/2005
    1/14/2005
    1/15/2005
    1/16/2005
    1/17/2005
    1/18/2005

    "alexandraVBAgirl" wrote:

    > Thanks, Bob, that seems to eliminate the error message. However, the
    > worksheet's startdate entered as 1/1/2005 initially turns to 12:00:00 AM as i
    > execute the macro. I got that before as well. Why does that happen?
    >
    > my worksheet view
    >
    > 1/1/2004 start date 12:00:00 AM
    > 1/2/2004 end date 2/2/2006
    > 1/1/2005
    > 1/2/2005
    > 1/3/2005
    > 1/4/2005
    > 1/5/2005
    > 1/6/2005
    > 1/7/2005
    > 1/8/2005
    > 1/9/2005
    > 1/10/2005
    > 1/11/2005
    > 1/12/2005
    > 1/13/2005
    > 1/14/2005
    > 1/15/2005
    > 1/16/2005
    > 1/17/2005
    > 1/18/2005
    >
    > Thanks.
    >
    >
    > "Bob Phillips" wrote:
    >
    > > This compiled for me
    > >
    > > Sub click()
    > >
    > > Dim counter As Integer
    > > Dim curCell As Date
    > > Dim startDate As Date
    > > Dim endDate As Date
    > >
    > >
    > > Range("e1").Value = startDate
    > >
    > > For counter = 1 To 20
    > > curCell = Worksheets("sheet1").Cells(counter, 3)
    > > If curCell < startDate Then curCell = 0
    > > Next counter
    > >
    > > End Sub
    > >
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "alexandraVBAgirl" <[email protected]> wrote in
    > > message news:[email protected]...
    > > > This code always gives me the error above. I have no idea what's wrong

    > > with
    > > > this
    > > > The point is to go through a list of dates and if they are less than say
    > > > 1/1/2005 (my start date entered in the spreadsheet) change them to 0 and
    > > > keep others as is. But this doesn't seem to work at all. Could anyone pls
    > > > help me? Thanks
    > > >
    > > > Sub click()
    > > >
    > > > Dim counter As Integer
    > > > Dim curCell As Date
    > > > Dim startDate As Date
    > > > Dim endDate As Date
    > > >
    > > >
    > > > Range("e1").Value = startDate
    > > >
    > > > For counter = 1 To 20
    > > > Set curCell = Worksheets("sheet1").Cells(counter, 3)
    > > > If curCell.Value < startDate.Value Then curCell.Value = 0
    > > > Next counter
    > > > End If
    > > >
    > > > End Sub

    > >
    > >
    > >


  6. #6
    Bob Phillips
    Guest

    Re: VBA Help needed -- compile error: object required

    I think you have bad logic

    This

    Range("e1").Value = startDate

    should maybe be

    startDate = Range("e1").Value

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "alexandraVBAgirl" <[email protected]> wrote in
    message news:[email protected]...
    > Thanks, Bob, that seems to eliminate the error message. However, the
    > worksheet's startdate entered as 1/1/2005 initially turns to 12:00:00 AM

    as i
    > execute the macro. I got that before as well. Why does that happen?
    >
    > my worksheet view
    >
    > 1/1/2004 start date 12:00:00 AM
    > 1/2/2004 end date 2/2/2006
    > 1/1/2005
    > 1/2/2005
    > 1/3/2005
    > 1/4/2005
    > 1/5/2005
    > 1/6/2005
    > 1/7/2005
    > 1/8/2005
    > 1/9/2005
    > 1/10/2005
    > 1/11/2005
    > 1/12/2005
    > 1/13/2005
    > 1/14/2005
    > 1/15/2005
    > 1/16/2005
    > 1/17/2005
    > 1/18/2005
    >
    > Thanks.
    >
    >
    > "Bob Phillips" wrote:
    >
    > > This compiled for me
    > >
    > > Sub click()
    > >
    > > Dim counter As Integer
    > > Dim curCell As Date
    > > Dim startDate As Date
    > > Dim endDate As Date
    > >
    > >
    > > Range("e1").Value = startDate
    > >
    > > For counter = 1 To 20
    > > curCell = Worksheets("sheet1").Cells(counter, 3)
    > > If curCell < startDate Then curCell = 0
    > > Next counter
    > >
    > > End Sub
    > >
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "alexandraVBAgirl" <[email protected]> wrote in
    > > message news:[email protected]...
    > > > This code always gives me the error above. I have no idea what's wrong

    > > with
    > > > this
    > > > The point is to go through a list of dates and if they are less than

    say
    > > > 1/1/2005 (my start date entered in the spreadsheet) change them to 0

    and
    > > > keep others as is. But this doesn't seem to work at all. Could anyone

    pls
    > > > help me? Thanks
    > > >
    > > > Sub click()
    > > >
    > > > Dim counter As Integer
    > > > Dim curCell As Date
    > > > Dim startDate As Date
    > > > Dim endDate As Date
    > > >
    > > >
    > > > Range("e1").Value = startDate
    > > >
    > > > For counter = 1 To 20
    > > > Set curCell = Worksheets("sheet1").Cells(counter, 3)
    > > > If curCell.Value < startDate.Value Then curCell.Value = 0
    > > > Next counter
    > > > End If
    > > >
    > > > End Sub

    > >
    > >
    > >




  7. #7
    Forum Contributor
    Join Date
    01-19-2006
    Posts
    142
    ok lets try

    Please Login or Register  to view this content.

  8. #8
    alexandraVBAgirl
    Guest

    Re: VBA Help needed -- compile error: object required

    thanks bob, i changed that in my previous post already.

    "Bob Phillips" wrote:

    > I think you have bad logic
    >
    > This
    >
    > Range("e1").Value = startDate
    >
    > should maybe be
    >
    > startDate = Range("e1").Value
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "alexandraVBAgirl" <[email protected]> wrote in
    > message news:[email protected]...
    > > Thanks, Bob, that seems to eliminate the error message. However, the
    > > worksheet's startdate entered as 1/1/2005 initially turns to 12:00:00 AM

    > as i
    > > execute the macro. I got that before as well. Why does that happen?
    > >
    > > my worksheet view
    > >
    > > 1/1/2004 start date 12:00:00 AM
    > > 1/2/2004 end date 2/2/2006
    > > 1/1/2005
    > > 1/2/2005
    > > 1/3/2005
    > > 1/4/2005
    > > 1/5/2005
    > > 1/6/2005
    > > 1/7/2005
    > > 1/8/2005
    > > 1/9/2005
    > > 1/10/2005
    > > 1/11/2005
    > > 1/12/2005
    > > 1/13/2005
    > > 1/14/2005
    > > 1/15/2005
    > > 1/16/2005
    > > 1/17/2005
    > > 1/18/2005
    > >
    > > Thanks.
    > >
    > >
    > > "Bob Phillips" wrote:
    > >
    > > > This compiled for me
    > > >
    > > > Sub click()
    > > >
    > > > Dim counter As Integer
    > > > Dim curCell As Date
    > > > Dim startDate As Date
    > > > Dim endDate As Date
    > > >
    > > >
    > > > Range("e1").Value = startDate
    > > >
    > > > For counter = 1 To 20
    > > > curCell = Worksheets("sheet1").Cells(counter, 3)
    > > > If curCell < startDate Then curCell = 0
    > > > Next counter
    > > >
    > > > End Sub
    > > >
    > > >
    > > > --
    > > > HTH
    > > >
    > > > Bob Phillips
    > > >
    > > > (remove nothere from email address if mailing direct)
    > > >
    > > > "alexandraVBAgirl" <[email protected]> wrote in
    > > > message news:[email protected]...
    > > > > This code always gives me the error above. I have no idea what's wrong
    > > > with
    > > > > this
    > > > > The point is to go through a list of dates and if they are less than

    > say
    > > > > 1/1/2005 (my start date entered in the spreadsheet) change them to 0

    > and
    > > > > keep others as is. But this doesn't seem to work at all. Could anyone

    > pls
    > > > > help me? Thanks
    > > > >
    > > > > Sub click()
    > > > >
    > > > > Dim counter As Integer
    > > > > Dim curCell As Date
    > > > > Dim startDate As Date
    > > > > Dim endDate As Date
    > > > >
    > > > >
    > > > > Range("e1").Value = startDate
    > > > >
    > > > > For counter = 1 To 20
    > > > > Set curCell = Worksheets("sheet1").Cells(counter, 3)
    > > > > If curCell.Value < startDate.Value Then curCell.Value = 0
    > > > > Next counter
    > > > > End If
    > > > >
    > > > > End Sub
    > > >
    > > >
    > > >

    >
    >
    >


  9. #9
    alexandraVBAgirl
    Guest

    Re: VBA Help needed -- compile error: object required

    Thanks gtì_jobert,
    with your code it worked just the way i wanted it to.

    "gti_jobert" wrote:

    >
    > ok lets try
    >
    >
    > Code:
    > --------------------
    >
    > Dim i%
    > Dim curCell As Date
    > Dim startDate As Date
    > Dim endDate As Date
    >
    > startDate = Range("e1").Value
    > endDate = Range("e2").Value
    >
    > Sheets("sheet1").Select
    >
    > i = 1
    > Do
    >
    > curCell = Cells(i, 3).Value
    > If curCell < startDate Then
    > Cells(i, 3).Value = 0
    > end if
    > i = i + 1
    > loop until i = 21
    >
    > End Sub
    >
    >
    > --------------------
    >
    >
    > --
    > gti_jobert
    > ------------------------------------------------------------------------
    > gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
    > View this thread: http://www.excelforum.com/showthread...hreadid=513551
    >
    >


+ 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