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)
Bookmarks