+ Reply to Thread
Results 1 to 2 of 2

Issue with If and Range statment.

  1. #1
    Registered User
    Join Date
    03-21-2014
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    15

    Issue with If and Range statment.

    Hi,

    I getting error in this line below from my code

    "If Rng1.Value >= 0 And Rng2.Value <= 999999 Then"

    Basically I want to calculate formula only if values are greater than 0 and less than 099999.

    Any help would be appriciated.

    Thanks,
    Vik


    'mycal() is function created by me to caluculate X.
    Sub mycal()

    Dim thecountX As Integer


    Dim Rng1 As range, Rng2 As range
    Set Rng1 = range("C1:C25")

    Set Rng2 = range("B1:B25")


    If Rng1.Value >= 0 And Rng2.Value <= 999999 Then

    'Here We are calculating value of X and storing in varilable "thecountX".
    thecountX = (range("C10") * range("C8") - range("C9") * range("B13")) / range("C10") + range("B13")

    Else
    MsgBox "Give value between 0 and 999999999999"
    End If


    'Here we are displaying the value of X from variable "thecountX".
    MsgBox "the count is " & thecountX

    'Endsub is used to end any function.
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Issue with If and Range statment.

    Hi, vop2311,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2012, 10:59 PM
  2. How to use an if statment to test for empty range
    By ducecoop in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-17-2008, 03:42 PM
  3. If statment to clear a range of cells
    By gthemerc in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-16-2008, 05:10 PM
  4. If Statment range
    By Merlin2007 in forum Excel General
    Replies: 1
    Last Post: 04-21-2007, 09:23 PM
  5. variable range in a COUNTIF statment
    By Sabean in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2006, 08:10 AM

Tags for this Thread

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