+ Reply to Thread
Results 1 to 4 of 4

Still having problem with IF-Then statement

  1. #1
    excelnut1954
    Guest

    Still having problem with IF-Then statement

    I hate to keep taking up space for this, but it just won't work for me.
    I've tried to work around it from a differnt angle, but damn, this
    should work! And, it seems it should be so simple. I really appreciate
    the reponses I've gotten on this problem. It's very frustrating. Here's
    the solution given to me before.... and I'm sure it's a good one. But,
    why doesn't it work for me?

    'If Range("Deleted_Today") = 0 Then
    ' FormatCells
    ' Else
    ' Move_Deleted_Records
    ' End If

    I want it to look at the range name "Deleted_Today". This is in a
    worksheet named Touches. It contains a formula that counts any entries
    in a column in a different worksheet, named Official List. Here's that
    formula:
    =COUNTA('Official List'!P6:P4366)

    If there are any entries in that column, the number will be more than 0
    in "Deleted_Today". If that is the case, I want the macro to go to the
    sub named FormatCells. If there is anything greater than 0 in
    "Deleted_Today", then it want it to go the sub named
    Move_Deleted_Records.

    However there is an error when I run it, and the 1st line of the
    statement is hightlighted. I've checked all the spellings. Should I
    specify the worksheets?

    I was given this statement as an alternative, but I get the same
    results.

    If Application.CountA(Range("Deleted_Today")) = 0 Then
    ' FormatCells
    ' Else
    ' Move_Deleted_Records
    ' End If

    Does it matter if there is a formula in that cell, or if it just a
    value? I even tried to replace the formula in "Deleted_Today" with a
    0. Same error.

    No sense in programming if you can't do a simple If-then. My
    spreadsheet designs are full of If-then formulas. It's the basic tool
    of spreadsheets design for me.
    Bob Phillips, you have given me alot of time, and have been very
    patient. If you, or anyone else can figure out what stupid mistake I'm
    making, I would greatly appreciate it.

    Thanks
    HELP!!


  2. #2
    cush
    Guest

    RE: Still having problem with IF-Then statement

    Try one of the following:

    If Sheeets("Touches").Range("Deleted_Today").Value = 0 Then
    FormatCells
    Else
    Move_Deleted_Records
    End If

    OR


    If Application.WorksheetFunction.CountA(Range("Deleted_Today")) = 0 Then
    FormatCells
    Else
    Move_Deleted_Records
    End If


    "excelnut1954" wrote:

    > I hate to keep taking up space for this, but it just won't work for me.
    > I've tried to work around it from a differnt angle, but damn, this
    > should work! And, it seems it should be so simple. I really appreciate
    > the reponses I've gotten on this problem. It's very frustrating. Here's
    > the solution given to me before.... and I'm sure it's a good one. But,
    > why doesn't it work for me?
    >
    > 'If Range("Deleted_Today") = 0 Then
    > ' FormatCells
    > ' Else
    > ' Move_Deleted_Records
    > ' End If
    >
    > I want it to look at the range name "Deleted_Today". This is in a
    > worksheet named Touches. It contains a formula that counts any entries
    > in a column in a different worksheet, named Official List. Here's that
    > formula:
    > =COUNTA('Official List'!P6:P4366)
    >
    > If there are any entries in that column, the number will be more than 0
    > in "Deleted_Today". If that is the case, I want the macro to go to the
    > sub named FormatCells. If there is anything greater than 0 in
    > "Deleted_Today", then it want it to go the sub named
    > Move_Deleted_Records.
    >
    > However there is an error when I run it, and the 1st line of the
    > statement is hightlighted. I've checked all the spellings. Should I
    > specify the worksheets?
    >
    > I was given this statement as an alternative, but I get the same
    > results.
    >
    > If Application.CountA(Range("Deleted_Today")) = 0 Then
    > ' FormatCells
    > ' Else
    > ' Move_Deleted_Records
    > ' End If
    >
    > Does it matter if there is a formula in that cell, or if it just a
    > value? I even tried to replace the formula in "Deleted_Today" with a
    > 0. Same error.
    >
    > No sense in programming if you can't do a simple If-then. My
    > spreadsheet designs are full of If-then formulas. It's the basic tool
    > of spreadsheets design for me.
    > Bob Phillips, you have given me alot of time, and have been very
    > patient. If you, or anyone else can figure out what stupid mistake I'm
    > making, I would greatly appreciate it.
    >
    > Thanks
    > HELP!!
    >
    >


  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Excelnut1954,

    Change this line: If Application.CountA(Range("Deleted_Today")) = 0 Then

    To: If WorksheetFunction.CountA(Range("Deleted_Today")) = 0 Then

    This should fix the problem provided Deleted_Today is a named Range. If not you will have to add the worksheet also. Just change Sheet1 to the name of the sheet the range is on.

    Alternate: If WorksheetFunction.CountA(Worksheets("Sheet1").Range(("Deleted_Today")) = 0 Then

    Sincerely,
    Leith Ross

  4. #4
    excelnut1954
    Guest

    Re: Still having problem with IF-Then statement

    Looks like the 1st option was successful. I was thinking of adding the
    sheet name, but I didn't know the proper syntax.
    I just don't know enought yet to explain why the other options given to
    me didn't work. I probably just didn't explain the layout well enough.
    If that's the case, then thanks for reading my mind to find out what I
    was after. Thanks Cush.

    Thankyou Bob Phillips & Leith Ross for your contributions. I save them
    all for future reference. I hope to learn this well enough to be able
    to contribute, and help someone like you guys do.

    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