select populated cells

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

i hate to ask this, because i'm sure it's come up a
million times before, but i've searched high and low and
couldn't find anything:

how do you select all of the populated cells of a
worksheet?
 
Dim rng1 as Range, rng2 as Range, rng3 as Range
On Error resume next
set rng1 = Activesheet.Cells.SpecialCells(xlconstants)
set rng2 = Activesheet.Cells.SpecialCells(xlFormulas)
On Error goto 0
if not rng1 is nothing and not rng2 is nothing then
set rng3 = Union(rng1,rng2)
elseif not rng1 is nothing then
set rng3 = rng1
elseif not rng2 is nothing then
set rng3 = rng2
End if
if not rng3 is nothing then
rng3.Select
End if
 

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