Hi,
I am trying to develop a simple module in order to select all the non empty cells in a given range. The script goes like this:
[VBA]Dim myrng(1500)
myrng(0) = ""
Set myrange = Range("A1:f10") 'a random range
col = myrange.Columns.Count
rws = myrange.Rows.Count
k = 0
n = -1
For i = 1 To rws
For j = 1 To col
If Cells(i, j).Value <> 0 Then
k = k + 1
n = n + 1
Cells(i, j).Activate
Cellz(k) = ActiveCell.Address
myrng(k) = myrng(n) & "Cellz(" & Str(k) & ")&"",""&"
End If
Next j
Next i
myrng(k) = Left(myrng(k), Len(myrng(k)) - 5)
rng = CStr(myrng(k))
Range(rng).Select
End Sub
[/VBA]
The vaule of rng is of the form cellz(1)&","&cellz(2)....&cellz(16)
I get the following error running this application
error:vba method range of object global failed
However, if instead i use directly:
rng=cellz(1)&","&cellz(2)...
this works fine.
I could really use some expert help on this since i am planning to use a similar provedure for a worksheet I use in my thesis.
Thanks in advance for any help
Kind Regards
Angelos