Help with Do While :(

  • Thread starter Thread starter artmajster
  • Start date Start date
A

artmajster

Function znajdz(gdzie, co_szukac)
Dim norma, wiersz As Double
wiersz = 2
gdzie.Activate ' activate Sheet
Range("A2").Select
norma = ActiveCell.Value

Do While co_szukac > norma
ActiveCell.Offset(1, 0).Select
MsgBox norma
norma = ActiveCell.Value
wiersz = wiersz + 1
Loop znajdz = wiersz

End Function
maby someone tell me what is wrong in this code ?
loop does not end when "norm" it gets biger from "co_szukac"
function is in Modul
 
It is hard to know exactly what's wrong because nearly all of your variables
are variants so when the
norma = ActiveCell.Value
is executed norma may be taking on a string value which may even have
leading spaces.

I suggest you avoid variants and actually specify each variable type as
below. Even if this does not fix the immediate problem I'm sure it will make
it clear what is wrong.

Function znajdz(gdzie as WorkSheet, co_szukac as Double)
Dim norma as Double, wiersz As Double
wiersz = 2
gdzie.Activate ' activate Sheet
Range("A2").Select
norma = ActiveCell.Value

Do While co_szukac > norma
ActiveCell.Offset(1, 0).Select
MsgBox norma
norma = ActiveCell.Value
wiersz = wiersz + 1
Loop
znajdz = wiersz

End Function
 
thx :)

it wont work with * co_szukac as Double*

but it works with *ByVal co_szukac as Double*

big thx :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top