ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Defining a range (https://www.excelbanter.com/excel-programming/288913-defining-range.html)

matt

Defining a range
 
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"

Bob Phillips[_6_]

Defining a range
 
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" wrote in message
...
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"




John Wilson

Defining a range
 
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" wrote in message
...
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"




Chip Pearson

Defining a range
 
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" wrote in message
...
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"





All times are GMT +1. The time now is 02:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com