LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default How to define a range based on first and last cells with data?

This is my first Excel macro. I can get this code to work on a defined range
like "A1:A10". But how can I code the macro to select the range by first and
last cells with data? This is my code so far...

Sub Macro1()

'1. Column reference will always be constant, rows will be variable
'2. Find first non-zero length cell
'3. Find the last cell with data
'4. Select range
'5. Make each value in selected range a working hyperlink


Dim FirstRow As Long
Dim LastRow As Long
FirstRow = Worksheets("Sheet1").Range("a1").End(xlDown).Row + 1 ' this
will give you the row of the 1st blank cell in A
LastRow = Worksheets("Sheet1").Range("a65536").End(xlUp).Row + 1 ' this
will give you the row of the last blank cell in A


Dim myRange As Range
Dim myVar As Range

'This is where I ran into trouble...
Set myRange = Range("A" & "'" & blankrow & "'" & ":A" & "'" & myvalue & "'"
& ") 'set range

myRange.Select


'Microsoft KB271856
For Each xCell In Selection
ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula
Next xCell

End Sub

--
Dennis
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to define a charts range based on the value of a cell chris Excel Discussion (Misc queries) 1 December 2nd 09 04:34 PM
Re-define a range in cells Geoff Excel Programming 0 June 1st 05 01:00 AM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
Define Range based on cell color StephanieH Excel Programming 6 December 15th 04 04:24 PM
Define a Dynamic Range Based on an Index Mike Roberto Excel Programming 4 August 5th 04 02:02 PM


All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"