Results 1 to 5 of 5

Macro with ranges based on border format

Threaded View

  1. #1
    Registered User
    Join Date
    02-20-2013
    Location
    Boston, Massachusetts
    MS-Off Ver
    365
    Posts
    13

    Macro with ranges based on border format

    This is an example of the sort of files I work on every week.

    - It is NEVER guaranteed that certain keywords will be in the same column from project to project.
    - But "Scenes Liked" and "Scenes Disliked" will ALWAYS be directly left to the regions in question.
    - Similarly, the regions in question will ALWAYS be formatted with borders (nothing else in the data set will).

    Border Example LD.JPG

    I need to change the contents of the FIRST bordered region (D1:M1) from the unique text in each cell to "sc1" "sc2" "sc3" etc.
    E.g. "Smith finds out he has a clone" CHANGES TO "sc1" / "Logos" CHANGES TO "sc2"

    And I need to change the contents of the SECOND bordered region (P1:Y1) from the unique text in each cell to "scd1" "scd2" "scd3" etc.
    E.g. "Smith finds out he has a clone" CHANGES TO "scd1" / "Logos" CHANGES TO "scd2"


    This is part of the code I've been using, located in a SEPARATE workbook.
    The macro finds "Scenes Liked," offsets by one, and sets the range as ActiveCell xlToRight.
    It then finds the FIRST cell in that range that does NOT contain a formatted border and inserts a blank column before performing its other functions.

    '''SCENES LIKED FORMAT'''
        Rows(1).Find("Scenes Liked").Offset(0, 1).Select
        Dim range1 As Range
        Set range1 = Range(ActiveCell, ActiveCell.End(xlToRight))
        
        range1.Activate
        Application.FindFormat.Borders(xlDiagonalDown).LineStyle = xlNone
        Application.FindFormat.Borders(xlDiagonalUp).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeLeft).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeTop).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeBottom).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeRight).LineStyle = xlNone
        
        range1.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=True).Activate
        
                Range(Selection, Selection.End(xlDown)).Insert Shift:=xlToRight
        
        Rows(1).Find("Scenes Liked").Offset(0, 1).Select
        ActiveCell.FormulaR1C1 = "sc1"
        ActiveCell.AutoFill Range(ActiveCell.Address, ActiveCell.End(xlToRight)), Type:=xlFillDefault
        
        range1.Activate
        Application.FindFormat.Borders(xlDiagonalDown).LineStyle = xlNone
        Application.FindFormat.Borders(xlDiagonalUp).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeLeft).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeTop).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeBottom).LineStyle = xlNone
        Application.FindFormat.Borders(xlEdgeRight).LineStyle = xlNone
        
        range1.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=True).Activate
                ActiveCell.Formula = "PlaceholderColumnForPivot"
    The same sort of code is then used for the SECOND region, "Scenes Disliked."



    Whenever I try running the macro I receive this error message:

    Capture.JPG


    And the debugger highlights this section of code:
    range1.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=True).Activate


    Any thoughts on how to fix this error or avoid it altogether with a different approach?
    (Macro file attached, specific to Private Sub PivotDomestic section)
    Attached Files Attached Files
    Last edited by sxj; 01-08-2020 at 11:28 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Add a border around multiple ranges which are dynamic
    By muss1210 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2017, 08:14 AM
  2. Format .. Border .. I need a thicker border
    By Trebor777 in forum Excel General
    Replies: 1
    Last Post: 10-26-2016, 09:41 AM
  3. [SOLVED] Excel Macro to Add Buttom Double Border to Rows Based on Criteria
    By eitan932 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-29-2016, 07:02 AM
  4. [SOLVED] Excel Macro to Add Buttom Double Border to Rows Based on Criteria
    By eitan932 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2014, 05:17 AM
  5. Format Border color based on value
    By jeff.p in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-05-2007, 04:13 PM
  6. [SOLVED] Conditional Format based on date ranges
    By Corey in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-31-2006, 12:40 AM
  7. Macro to Conditionally format Thick Border
    By nuver in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-06-2005, 08:05 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