Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default applying a macro for a specific field to a range of fields

I have a macro that takes information from two columns and builds a
hyperlink in another column. I'm pretty new at this, so while I was
writing the macro I wrote it for one specific cell, using information
from two other cells. I want to expand the macro so that it applies to
every cell in the column, but I don't know how to do this. Can anyone
show me how, here's what I have so far.

Sub makehyperlinks()
Range("E2").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:="c:\test\job" & Range("B2") & "-" & Format(Range("A2"),
"yyyy-mm-dd") & "TimeCard" & ".xls", TextToDisplay:="File"

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default applying a macro for a specific field to a range of fields

Sub makehyperlinks()
Dim Lrow As Long
Dim rng As Range
Dim c As Range
Lrow = Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range("E2:E" & Lrow)
For Each c In rng
ActiveSheet.Hyperlinks.Add Anchor:=c, Address:= _
"c:\test\job" & Range("B"& Lrow) & "-" & Format(Range("A"& Lrow), _
"yyyy-mm-dd") & "TimeCard" & ".xls", TextToDisplay:="File"
Next c
End Sub

Untested, but same layout as some code I use. I use String Variables in the
Address:= instead of cell references.
For example: Add 2 more variables
Dim myString As String, myDate As String
Then following the For Each line
For Each c In rng
myString = c.Offset(0,-3).Value 'Col B
myDate = c.Offset(0,-4).Value 'Col A
ActiveSheet.Hyperlinks.Add Anchor:=c, Address:= _
"c:\test\job" & myString & "-" & Format(myDate), _
"yyyy-mm-dd") & "TimeCard" & ".xls", TextToDisplay:="File"
Next c

You may have better luck using it this way.
Mike F

"Craig" wrote in message
ups.com...
I have a macro that takes information from two columns and builds a
hyperlink in another column. I'm pretty new at this, so while I was
writing the macro I wrote it for one specific cell, using information
from two other cells. I want to expand the macro so that it applies to
every cell in the column, but I don't know how to do this. Can anyone
show me how, here's what I have so far.

Sub makehyperlinks()
Range("E2").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:="c:\test\job" & Range("B2") & "-" & Format(Range("A2"),
"yyyy-mm-dd") & "TimeCard" & ".xls", TextToDisplay:="File"

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default applying a macro for a specific field to a range of fields

You can do this without a macro using the Hyperlink worksheet function.

Write the formula, then drag fill down the column.

See Excel help for details.

--
Regards,
Tom Ogilvy

"Craig" wrote in message
ups.com...
I have a macro that takes information from two columns and builds a
hyperlink in another column. I'm pretty new at this, so while I was
writing the macro I wrote it for one specific cell, using information
from two other cells. I want to expand the macro so that it applies to
every cell in the column, but I don't know how to do this. Can anyone
show me how, here's what I have so far.

Sub makehyperlinks()
Range("E2").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:="c:\test\job" & Range("B2") & "-" & Format(Range("A2"),
"yyyy-mm-dd") & "TimeCard" & ".xls", TextToDisplay:="File"

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default applying a macro for a specific field to a range of fields

Thanks for the replies.

I've tried Mike's first code, and it just puts the same link in every
cell.

Tom - I tried to use the formula, but one of the parts of the filename
is a date, so the file name would be c:\test\job6-2004-06-02.xls and
the formula links to c:\test\job6-38140.xls

I'm trying Mike's second code now . . .

Reply
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
Macro - specific range puiuluipui Excel Discussion (Misc queries) 3 May 10th 09 11:33 AM
copy field settings of a field to other fields in same pivot tbl new22007 Excel Worksheet Functions 0 May 8th 08 10:22 PM
Need help - Macro to copy a specific range Dileep Chandran Excel Worksheet Functions 9 December 5th 06 09:10 AM
Need help - Macro to copy a specific range Dileep Chandran Excel Worksheet Functions 0 December 4th 06 10:24 AM
Getting a Select Range class field during a macro setup ssciarrino Excel Programming 1 August 22nd 05 06:15 PM


All times are GMT +1. The time now is 03:04 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"