PDA

View Full Version : [SOLVED] Using a Cell Value as a counter limit



Scannerman
11-18-2004, 05:21 AM
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.

Jacob Hilderbrand
11-18-2004, 05:28 AM
You're close:


Val(Range("E1").Value)

Scannerman
11-18-2004, 06:01 AM
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.

Jacob Hilderbrand
11-18-2004, 06:20 AM
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.

Zack Barresse
11-18-2004, 10:59 AM
Don't ya just hate that? :yes


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).