+ Reply to Thread
Results 1 to 4 of 4

find within a named range, then deselect the range

Hybrid View

  1. #1
    Bob Mouldy
    Guest

    find within a named range, then deselect the range

    I'm writing a macro to format column headers and adjust column widths.

    The question i want to ask is, "how do I deselect the named range i
    just searched within, keeping the cursor on the cell I found."

    Essentially...
    (the header row is a named range, "Headers")
    1. Goto "Headers"
    2. Find "HeaderTitle3" (this avoids finding instances elsewhere on the
    sheet)
    3. ...then i would like to:
    a.) apply Bold for this cell only
    b.) adjust the column width to "10"

    Problem: at step 3, the named range "Headers" is still selected, and
    all formatting applied affects everything within this range (all the
    headers).

    Is there a command i can use to de-select the named range, after i find
    the cell within it i need?

    One note: a problem i'm addressing is that rows and columns will be
    added to this sheet. Therefore, if I name a cell "D2" in the script,
    then add a column (C), then the reference is incorrect.
    > To de-select the range, I tried using the arrow keys to move up 1

    cell, then down 1 cell, but in the recorded Macro, it simply named the
    cell that was selected ( Range("D2").Select ) so that's not a solution.
    > Custom Views seems to use cell references as well; after inserting

    a new column, then selecting a custom view, the formatting is applied
    to the wrong columns (still applied to column D, after I insert a new
    column C and push it over to become D)
    > I'd rather avoid naming the individual columns as named

    ranges/cells, because i have almost 200 columns.

    thx,
    bob


  2. #2
    NickHK
    Guest

    Re: find within a named range, then deselect the range

    Bob,
    Not sure what you are currently doing as you didn't post but..
    It's seldom necessary to .Select objects in order to use them, so if .select
    is causing you trouble, don't.
    <air code>
    Dim FindHeader as range
    set FindHeader= Worksheets("Whatever").range("Headers").find(HeaderName)
    with FindHeader
    .font.bold=true
    .entirecolumn.width=10
    end with
    <air code>
    Add code in case FindHeader is not found.

    NickHK

    "Bob Mouldy" <bmouldy@gmail.com>
    ???????:1156249188.837828.282880@74g2000cwt.googlegroups.com...
    > I'm writing a macro to format column headers and adjust column widths.
    >
    > The question i want to ask is, "how do I deselect the named range i
    > just searched within, keeping the cursor on the cell I found."
    >
    > Essentially...
    > (the header row is a named range, "Headers")
    > 1. Goto "Headers"
    > 2. Find "HeaderTitle3" (this avoids finding instances elsewhere on the
    > sheet)
    > 3. ...then i would like to:
    > a.) apply Bold for this cell only
    > b.) adjust the column width to "10"
    >
    > Problem: at step 3, the named range "Headers" is still selected, and
    > all formatting applied affects everything within this range (all the
    > headers).
    >
    > Is there a command i can use to de-select the named range, after i find
    > the cell within it i need?
    >
    > One note: a problem i'm addressing is that rows and columns will be
    > added to this sheet. Therefore, if I name a cell "D2" in the script,
    > then add a column (C), then the reference is incorrect.
    > > To de-select the range, I tried using the arrow keys to move up 1

    > cell, then down 1 cell, but in the recorded Macro, it simply named the
    > cell that was selected ( Range("D2").Select ) so that's not a solution.
    > > Custom Views seems to use cell references as well; after inserting

    > a new column, then selecting a custom view, the formatting is applied
    > to the wrong columns (still applied to column D, after I insert a new
    > column C and push it over to become D)
    > > I'd rather avoid naming the individual columns as named

    > ranges/cells, because i have almost 200 columns.
    >
    > thx,
    > bob
    >




  3. #3
    Andy Packard
    Guest

    Re: find within a named range, then deselect the range

    Thanks, this is really helpful.

    I'm getting a debug error on the .EntireColumn line. I'm not a
    programmer... is there something simple that's wrong about this line of
    code? When I remove it, the command works fine (bold-facing the correct
    header).

    Sub Test()
    '
    ' Test Macro
    ' Macro recorded 8/22/2006 by Bob Mouldy
    '
    ' Keyboard Shortcut: Ctrl+Shift+T
    '

    Dim FindHeader As Range
    Set FindHeader = Worksheets("Sheet1").Range("Headers").Find("Channel")
    With FindHeader
    .Font.Bold = True
    .EntireColumn.Width = 10
    End With

    End Sub

    thx,
    bob


  4. #4
    Bob Mouldy
    Guest

    Re: find within a named range, then deselect the range

    Thanks, this is really helpful.

    I'm getting a debug error on the .EntireColumn line. I'm not a
    programmer... is there something simple that's wrong about this line of
    code? When I remove it, the command works fine (bold-facing the correct
    header).

    Sub Test()
    '
    ' Test Macro
    ' Macro recorded 8/22/2006 by Bob Mouldy
    '
    ' Keyboard Shortcut: Ctrl+Shift+T
    '

    Dim FindHeader As Range
    Set FindHeader = Worksheets("Sheet1").Range("Headers").Find("Channel")
    With FindHeader
    .Font.Bold = True
    .EntireColumn.Width = 10
    End With

    End Sub

    thx,
    bob


+ 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