Consulting

Results 1 to 5 of 5

Thread: Using a Cell Value as a counter limit

  1. #1
    VBAX Regular
    Joined
    Nov 2004
    Location
    Coventry, UK
    Posts
    8
    Location

    Using a Cell Value as a counter limit

    Hi. I guess there's a pretty simple answer to this but I can't see it.

    I want to use a counter in my Macro that ends when the counter reaches the value of a given cell. Obviously the conter is an integer so the value of the cell must be an integer but when I debug I get a "type mismatch" error. I'm guessing that the cell value is returned as a string rather than an integer.

    Ok so here's the problem. How do I convert my cell value string to an integer to use in my counter?

    I've tried "Value(Range("E1").Value)" but I get a "Sub or Function not defined" error, so the Value function is not availble. Any other ideas would be gratefully received.

    PS In the attached if I change Hundreds, Fiftys & Twentys to numeric constants it runs fine (i.e Humdreds = 7; Fiftys = 4; Twentys = 5) but I wnt to be able to change the values from the spreadsheet.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're close:

    Val(Range("E1").Value)

  3. #3
    VBAX Regular
    Joined
    Nov 2004
    Location
    Coventry, UK
    Posts
    8
    Location
    Thanks very much for that. I couldn't find "Val" on MSDN with any of the searches I tried.

    The real problem however was my stupidity. I was looking at E1,F1 & G1 instead of E2,F2 & G2. Doh!

    Donkey!!!

    Using Val() did show me where I'd gone wrong though so many thanks.

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

    P.S I also hate it when my code does exactly what I wrote it to do instead of what I wanted it to do.

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Don't ya just hate that?


    Scannerman, I'll go ahead and mark this thread as Solved. You can do so on any threads you start by going to Thread Tools --> Mark Solved --> Perform Action (just fyi).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •