Find(What:=

bsquad

Board Regular
Joined
Mar 15, 2016
Messages
194
I am sure this is just the dumbest thing I am overlooking, but does anyone have any insight as to why this first one works and the second brings back a error 91 Object variable or with block variable not set. Both my variables or 'Set' are declared as Ranges - hence having a .Row and a .Column in the MsgBox



Code:
            Application.FindFormat.Clear
            Application.FindFormat.Interior.Color = RGB(216, 219, 216)
    Set zRGB216 = ActiveSheet.Columns("A:AA").Find(What:="*", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, MatchByte:=False, _
                                                            SearchFormat:=True)
MsgBox (zRGB216.Row)

Code:
            Application.FindFormat.Clear
            Application.FindFormat.Borders(xlEdgeRight).Weight = xlMedium
    Set xlBorder = ActiveSheet.Columns("A:AA").Find(What:="*", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False, MatchByte:=False, SearchFormat:=True)
MsgBox (xlBorder.Columns)
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
What happens if you remove the s from Columns?
 
Upvote 0
I am sure this is just the dumbest thing I am overlooking, but does anyone have any insight as to why this first one works and the second brings back a error 91 Object variable or with block variable not set. Both my variables or 'Set' are declared as Ranges - hence having a .Row and a .Column in the MsgBox

Code:
            Application.FindFormat.Clear
            Application.FindFormat.Borders(xlEdgeRight).Weight = xlMedium
    Set xlBorder = ActiveSheet.Columns("A:AA").Find(What:="*", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False, MatchByte:=False, SearchFormat:=True)
MsgBox (xlBorder.Column[B][COLOR="#FF0000"][SIZE=4]s[/SIZE][/COLOR][/B])
Try removing the red highlighted "s"
 
Last edited:
Upvote 0
thank you for the responses;

to answer both of you, i get the same error for each. If there is an alternative way I am open to that as well. I would just like to avoid using SpecialCells(xlLastCell) and UsedRange - just because as soon as a user almost even touches a cell outside the desired area it changes both.
 
Upvote 0
Not sure that FindFormat works with borders, but try this
Code:
    Dim Usdrws As Long
    Dim UsdCols As Long

    Usdrws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    UsdCols = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Not sure that FindFormat works with borders, but try this
Code:
    Dim Usdrws As Long
    Dim UsdCols As Long

    Usdrws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    UsdCols = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Fluff I think your UsdCols will work, I appreciate it!
:confused: Do you mean the cells having a right border was not a requirement? You only wanted to find the last used cell?
 
Upvote 0
Hi Rick, no having a border was a requirement; I did not want to use UsedRange, its likely users will mess with cells outside of the the visible used range and will end up deleting it. If you had any further input I am open.
 
Upvote 0
I am getting UsedRange.Rows.Count and SpecialCells(xlCellTypeLastCell).Row mixed up with each other, so I think I will be ok using UsedRange without FindFormat / Find, but if anyone has additional ways to use FindFormat / Find with Borders I am open to hear it.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top