Excel VBA setting Ranges

  • Thread starter Thread starter Malcolm Hind
  • Start date Start date
M

Malcolm Hind

I would like to change the first Cell and the last Cell of a Range using
VBA

I have this code;

Dim MyRange As Range
Set MyRange = Selection

lets say the selection was ($A$1:$H$3), so I now have a MyRange of $A$1:$H
$3 and using;

MsgBox "My Range is " & MyRange.Address

I get a message that says that this is true.

Now I want to change the first Cell ($A$1) or the last Cell ($H$3) to
something different so I have tried these variations;

MyRange = Range(MyRange(1, 1).Address, H13) - Also tried using 'Set'
Set MyRange = Range("H3", "K8")

but using the message after either of these lines shows that the original
range limit is still applying.

Can anyone tell me how to set the first or last cell properties using VBA ?

Any help appreciated

Thanks
 
MyRange(RowIndex:=2), MyRange(RowIndex:=MyRange.Rows.Count - 1

Ron, Thanks for that input - I have a couple of (sort of) follow up questions
but I will post them seperately.
 
Further to Ron's`suggestion, perhaps...

Dim MyRange As Range
Set MyRange = Selection
With MyRange
.Cells(1) = 123: .Cells(,Cells.Count) = 456
End With 'MyRange

-OR- simply...

With Selection
.Cells(1) = 123: .Cells(,Cells.Count) = 456
End With 'Selection

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 

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

Similar Threads

VBA help PLEASE 5
NEXT 11
MIKE H i need more help 1
do while loop problem 4
Evaluate value of cell to determine fill upwards 2
Excel VBA 1
Problem using Range objects 1
Excel VBA vlookup 1

Back
Top