Defining a range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to define a particular range of cells so that you can just refer to the range name in the code? This is what I tried, however it didn't work. Also, if I can do this, when I use it in the code would I just put " selectrng.value = "" "if I want it to clear out all of the values in the range? Thanks. I tried it with parentheses and without and it still wouldn't work.


Dim selectrng as Range "D10:D15,F10:F15,H10:H15"
 
Dim selectrng as Range

Set selectrng = Range("D10:D15,F10:F15,H10:H15")

selectrng.Value = ""

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Matt said:
Is it possible to define a particular range of cells so that you can just
refer to the range name in the code? This is what I tried, however it didn't
work. Also, if I can do this, when I use it in the code would I just put "
selectrng.value = "" "if I want it to clear out all of the values in the
range? Thanks. I tried it with parentheses and without and it still wouldn't
work.
 
Matt,

Try this:

Sub TestMe()
Dim selrange As Range
Set selrange = Range("D10:D15,F10:F15,H10:H15")
selrange.Activate
End Sub

The .Activate is just to show you that the range exists as
it isn't a named range (it won't show up on your range list).

If you want it named, use something like this:
selrange.Name = "testrange"

John


Matt said:
Is it possible to define a particular range of cells so that you can just
refer to the range name in the code? This is what I tried, however it didn't
work. Also, if I can do this, when I use it in the code would I just put "
selectrng.value = "" "if I want it to clear out all of the values in the
range? Thanks. I tried it with parentheses and without and it still wouldn't
work.
 
Matt,

Try something like

Dim Rng As Range
Set Rng = Range("D10:D15,F10:F15,H10:H15")
Rng.ClearContents


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


Matt said:
Is it possible to define a particular range of cells so that
you can just refer to the range name in the code? This is what I
tried, however it didn't work. Also, if I can do this, when I
use it in the code would I just put " selectrng.value = "" "if I
want it to clear out all of the values in the range? Thanks. I
tried it with parentheses and without and it still wouldn't work.
 
Back
Top