Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to build a range from the last occupied cell in column?

Status
Not open for further replies.

Rexxx

MIS
Oct 16, 2001
47
What is the VB command to build a range beginning with the last occupied cell in a certain column plus 170 rows?
 
Rexxx,

I first submitted the following routine in the Microsoft Office forum - thread68-363648.

This routine will do the job...

It requires that you first assign a range name to the "certain column" you refer to. I've used the name "cert_colm".

Then, when you run the routine, it will:
a) assign the range name "cert_range" to the range you requested, and
b) highlight that range in yellow.

You will probably want to modify these names and color to suit your own needs. They are only intended as examples.

Sub Set_Range()
Application.Goto Reference:="cert_colm"
curcolm = ActiveCell.Column
FirstCell = Cells(65536, curcolm).End(xlUp).Address
LastCell = Cells(65536, curcolm).End(xlUp).Offset(170, 0).Address
Data_Range = FirstCell & ":" & LastCell
Range(Data_Range).Name = "cert_range"
Application.Goto Reference:="cert_range"
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub

I hope this is what you wanted. Please advise as to how it fits.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
As always, there is more than one way to skin a cat, though this is only very slightly different from Dale's suggestion

Code:
Sub liminal()
Dim iCol As Integer
Dim lRow As Long
iCol = ActiveCell.Column
lRow = Cells(65536, iCol).End(xlUp).Row
Range(Cells(lRow, iCol), Cells(lRow + 170, iCol)).Name = "hullaballoo"
Range("hullaballoo").Interior.Color = vbRed
End Sub

One thing to watch for is that if your last data row is greater than 65366 the routine will lie down and die. DEAD!

And so ends my (shortened)lunch time special for today.

Happy Friday - to you all
(bored? me??)

;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top