+ Reply to Thread
Results 1 to 2 of 2

Relative Macro to Name a cell the contents of that cell.

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2008
    Location
    Space
    Posts
    14

    Relative Macro to Name a cell the contents of that cell.

    Basically using the "record Macro" function with relative references on i select my first cell, hit "Define Name" and it defaults to the cell contents, then I hit Ok, move right to next column, rinse and repeat until my row is done.

    The problem is, when I go to the next row to run the macro, it won't name the cells anything. I believe it is trying to name these cells the same names as the row above it. How do I get Excel to understand that I want the cells named by their contents?

    Thanks!

    Here is the Code the record macro function produced. I'm not Microsoft Visual Basic proficient, please help!

    Sub CELLNAMETest1()
    '
    ' CELLNAMETest1 Macro
    '
    ' Keyboard Shortcut: Ctrl+q
    '
        ActiveWorkbook.Names.Add Name:="pre1a", RefersToR1C1:= _
            "='BidPackageSelection NEW '!R29C6"
        ActiveWorkbook.Names("pre1a").Comment = ""
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveWorkbook.Names.Add Name:="pre1b", RefersToR1C1:= _
            "='BidPackageSelection NEW '!R29C7"
        ActiveWorkbook.Names("pre1b").Comment = ""
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveWorkbook.Names.Add Name:="pre1c", RefersToR1C1:= _
            "='BidPackageSelection NEW '!R29C8"
        ActiveWorkbook.Names("pre1c").Comment = ""
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveWorkbook.Names.Add Name:="pre1d", RefersToR1C1:= _
            "='BidPackageSelection NEW '!R29C9"
        ActiveWorkbook.Names("pre1d").Comment = ""
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveWorkbook.Names.Add Name:="pre1e", RefersToR1C1:= _
            "='BidPackageSelection NEW '!R29C10"
        ActiveWorkbook.Names("pre1e").Comment = ""
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveWorkbook.Names.Add Name:="pre1f", RefersToR1C1:= _
            "='BidPackageSelection NEW '!R29C11"
        ActiveWorkbook.Names("pre1f").Comment = ""
        ActiveCell.Offset(0, 1).Range("A1").Select
        ActiveWorkbook.Names.Add Name:="pre1g", RefersToR1C1:= _
            "='BidPackageSelection NEW '!R29C12"
        ActiveWorkbook.Names("pre1g").Comment = ""
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,629

    Re: Relative Macro to Name a cell the contents of that cell.

    Option Explicit
    
    Sub test()
        Dim Col As Long
        For Col = 7 To 12
            On Error Resume Next
            ActiveWorkbook.Names.Add _
                Name:=ActiveCell.Value, _
                RefersToR1C1:="='BidPackageSelection NEW'!R" & ActiveCell.Row & "C" & Col
            If Err.Number > 0 Then Debug.Print Err.Description
            Err.Clear
            ActiveCell.Offset(0, 1).Select
        Next Col
    End Sub
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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