Select Range

  • Thread starter Thread starter Mike H.
  • Start date Start date
M

Mike H.

In my code I determine a range that I wish to select. What is the proper
syntax to select that range. Let's say I wish to add a line to all cells
selected. This does not work:
My hope would be to have every cell from 11,1 to 65,7 selected but I get an
error on the line Range(PrtRng).select. Ideas?

Dim PrtRng as Range
Dim X as Double
let X=65
Set PrtRng = Range(Cells(11, 1), Cells(X, 7))
Range(PrtRng).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
 
Sub mersion()
Dim PrtRng As Range
Dim X As Double
Let X = 65
Set PrtRng = Range(Cells(11, 1), Cells(X, 7))
PrtRng.Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

End Sub

You don't need the RANGE() in the Select line because PrtRng is already a
range.


You use RANGE() to convert an address (usually a String) into a range.
 
Dim PrtRng As Range
Dim X As Double
Let X = 65
Set PrtRng = Range(Cells(11, 1), Cells(X, 7))
With PrtRng
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
In my code I determine a range that I wish to select.  What is the proper
syntax to select that range.  Let's say I wish to add a line to all cells
selected.  This does not work:
My hope would be to have every cell from 11,1 to 65,7 selected but I get an
error on the line Range(PrtRng).select.  Ideas?

Dim PrtRng as Range
Dim X as Double
let X=65
Set PrtRng = Range(Cells(11, 1), Cells(X, 7))
Range(PrtRng).Select
With Selection.Borders(xlEdgeBottom)
     .LineStyle = xlContinuous
     .Weight = xlThin
     .ColorIndex = xlAutomatic
End With

Hi
The Syntax Range(something) expects the something to be text e.g.
Range ("A1:B10"). You have already set your range object PrtRng so you
simply do

PrtRng.Select

(which, if you were a bit perverse, you might write as
Range(PrtRng.Address).Select if you want to see the text in there)

Note that you don't need to select the range object to work with it.
You could simply do

With PrtRng.Borders(xlEdgeBottom)
etc

regards
Paul
 

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