Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Loop while skipping blanks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jhahes - 21 Mar 2006 21:29 GMT
How do I do the following?

I want to convert text to a number but skip the blanks in a range

this is what I have, but it debugs because I have blanks

Range("C2").select
Do
activecell.value = clng(activecell.value)
activecell.offset(1,0).select
Loop Until activecell.row = 500

How do I skip the empty or blank cells but still loop the code to cel
500.

Thank you for any help

Jos
Toppers - 21 Mar 2006 22:00 GMT
try:

For Each cell In Range("C2:C500")
If cell.Value <> "" Then cell.Value = CLng(cell.Value)
Next

(Xl2003: blanks give value of 0)

HTH

> How do I do the following?
>
[quoted text clipped - 14 lines]
>
> Josh
Duke Carey - 21 Mar 2006 22:00 GMT
dim x as int

x=0
with Range("C2")
Do
 if  len( .offset(x,0))>0 then .offset(x,0).value = clng(.offset(x,0))
  x=x+1    
Loop Until x=499

end with

> How do I do the following?
>
[quoted text clipped - 14 lines]
>
> Josh
jhahes - 22 Mar 2006 19:09 GMT
Hi Toppers, I tried your solution and it made me debug. It state
variable not defined with the word cell highlighted in yellow.

Duke, I also tried your solution and it gave me a debug error of typ
mismatch with .offset(x,0).value highlighted in yellow.

Can you please help...

Thanks...

Jos
Toppers - 22 Mar 2006 19:29 GMT
Post your code OR if you have set Option Explicit then add

Dim cell as range

to the macro.

> Hi Toppers, I tried your solution and it made me debug. It stated
> variable not defined with the word cell highlighted in yellow.
[quoted text clipped - 7 lines]
>
> Josh
jhahes - 22 Mar 2006 19:53 GMT
Toppers,

I put in the dim cell as range

and I am getting Run-time error '13': Type Mismatch

Here is my complete code

If Sheet2.Visible = xlSheetHidden Then
Sheet2.Visible = xlSheetVisible
End If
Sheet2.Activate
Range("A2").Select
Do
ActiveCell.Value = CLng(ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = ""

Dim cell As Range
For Each cell In Range("C2:C500")
If cell.Value <> "" Then cell.Value = CLng(cell.Value)
Next

Thanks for any help.....

Jos
Toppers - 22 Mar 2006 21:46 GMT
Your code worked OK for me but I am confused. In your original posting you
were looping through column C for 500 rows... now you are looping through
column A. So my code appears to be redundant. Any errors (Type mismatch) are
probably due to the data in column C (or A)i.e. non-numeric data which cannot
be converted to LONG.

> Toppers,
>
[quoted text clipped - 22 lines]
>
> Josh
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.