+ Reply to Thread
Results 1 to 5 of 5

If statement doesn't work for range?

  1. #1
    Registered User
    Join Date
    01-09-2007
    Posts
    54

    If statement doesn't work for range?

    I was wondering if anyone could tell me why this code doesn't work? I'm just playing around with some codes to see what can work.

    Please Login or Register  to view this content.
    Private Sub CommandButton1_Click()
    myRng = Range("a1", Range("a1").End(xlDown)).value
    If myRng = 2 Then
    MsgBox ("yes")
    End If
    End Sub
    Please Login or Register  to view this content.
    The following code does work

    Please Login or Register  to view this content.
    Range("a1", Range("a1").End(xlDown)).value = 2

    This sets the whole range of cells to 2, so why can't you call an IF statement to see what the value is?

    Alex
    Last edited by deeppurple247; 02-07-2007 at 05:47 PM.

  2. #2
    Registered User
    Join Date
    01-09-2007
    Posts
    54

    if statement doesn't work for range?

    I was wondering if anyone could tell me why this code doesn't work? I'm just playing around with some codes to see what can work.

    Please Login or Register  to view this content.
    The following code does work

    Please Login or Register  to view this content.
    This sets the whole range of cells to 2, so why can't you call an IF statement to see what the value is?

    Alex

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565
    Hi Alex,

    Sorry, do you want to know the value of the last cell in your range variable or something else?

    Cheers,

    Robert

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    If you are trying to obtain the value of the sum of your range, then try:
    Please Login or Register  to view this content.
    If you are trying to obtain the value of the last cell in the range, then try:
    Please Login or Register  to view this content.
    HTH

    Jason
    Last edited by jasoncw; 02-07-2007 at 06:53 PM.

  5. #5
    Registered User
    Join Date
    01-18-2007
    Posts
    21
    you have to check each cell individually


    Please Login or Register  to view this content.

+ 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