Method 'Range' of object '_Global' failed

M

Mohanasundaram

Hi All,

I have the following code in my Excel Macro.
While running this macro I am getting the following error
"Method 'Range' of object '_Global' failed"
What is wrong with this code

Dim i As Long
Dim s As String
i = 1

While (1)
s = "G" + CStr(i)
If Range(s).Value = "Completed" Then
Range(s).EntireRow.Hidden = True
End If

i = i + 1
Wend

Regards,
Moahn.
 
J

John

Mohanasundaram,

No termination possible with "While (1)"

try -

Dim i As Long
Dim s As String
i = 1

While (i <= Cells.Rows.Count)
s = "G" + CStr(i)
If Range(s).Value = "Completed" Then
Range(s).EntireRow.Hidden = True
End If

i = i + 1
Wend

regards,

John
 

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

Top