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)
 
...but if anyone has additional ways to use FindFormat / Find with Borders I am open to hear it.
Code:
[table="width: 500"]
[tr]
	[td]Sub FindRightmostCellWithRightBorder()
  Dim LastRightBorderCell As Range
  Application.FindFormat.Clear
  With Application.FindFormat.Borders(xlRight)
      .LineStyle = xlContinuous
      .ColorIndex = 0
      .TintAndShade = 0
      .Weight = xlThin
  End With
  Application.FindFormat.Borders(xlBottom).LineStyle = xlNone
  Application.FindFormat.Borders(xlDiagonalDown).LineStyle = xlNone
  Application.FindFormat.Borders(xlDiagonalUp).LineStyle = xlNone
  Set LastRightBorderCell = ActiveSheet.UsedRange.Find("", , , , xlByColumns, xlPrevious, SearchFormat:=True)
  Application.FindFormat.Clear
  
  MsgBox "Rightmost cell with a right border: " & LastRightBorderCell.Address(0, 0)
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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