+ Reply to Thread
Results 1 to 3 of 3

Cleaning up code/avoid selecting

Hybrid View

  1. #1
    Registered User
    Join Date
    03-11-2008
    Posts
    34

    Cleaning up code/avoid selecting

    Hello Everyone,

    Could someone help me clean up the code below? I am selecting cells, and I think that could be avoided.

    What this does is inserts a hyperlink in N46 that points to another worksheet in the same workbook. Then it copies the formatting from the cell above.

    Dim TbName As String
    Dim ClntName As String
    TbName = Sheets("Controls").Range("O46").Value
    ClntName = Sheets("Controls").Range("N46").Value
    
    With Worksheets("Controls")
        .Range("N46").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
            "'" & TbName & "'!Template", TextToDisplay:=ClntName
        Range("N45").Select
        Selection.Copy
        Range("N46").Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
    End With

    I have started the cleanup, but I am not sure how to deal with the hyperlink statement and the formatting statment.

    Thanks for your help.

  2. #2
    Forum Contributor
    Join Date
    04-30-2008
    Posts
    105
    Try:

    Dim TbName As String
    Dim ClntName As String
    TbName = Sheets("Controls").Range("O46").Value
    ClntName = Sheets("Controls").Range("N46").Value
    
    With Worksheets("Controls")
        .Range("N46").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
            "'" & TbName & "'!Template", TextToDisplay:=ClntName
        Range("N45").Copy
        Range("N46").PasteSpecial (xlPasteFormats)
        Application.CutCopyMode = False
    End With
    As far as I know, with hyperlinks, you always have to have Excel select a cell otherwise it'll place a hyperlink in which cell is the ActiveCell.
    Last edited by fecurtis; 06-04-2008 at 01:28 PM.

  3. #3
    Registered User
    Join Date
    03-11-2008
    Posts
    34
    Thank you! I think you are right about hyperlinks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2007, 05:18 PM
  2. Selecting All Buttons
    By jonn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-28-2007, 09:17 PM
  3. Selecting column of the active cell
    By cheaperThanAPro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-26-2007, 10:04 PM
  4. Selecting the Toolbar components.
    By gajendra.gupta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2007, 10:37 AM
  5. Selecting a graph using macro
    By Dagwood2005 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-20-2007, 05:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1