0

Getting a runtime error for the variable ws. Tried almost everything i.e. changing the variable type, using Set to declare etc... Please help!

Sub program()
    Dim var1 As String,  wb As Workbook, SVlink As String, SAlink As String, ws As Range
    Application.ScreenUpdating = False
    Application.Calculation = xlManual

    With ActiveWorkbook.ActiveSheet
        x = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address  ‘using the address of the button to
        'perform some operation
    
        var1 = Range(x).Offset(-17, 8).Address
        x = Range(x).Offset(-13, 8).Address
        y = Range(x).Offset(12, 0).Address
        Set ws = Range(x, y).find(what:="Nothing found")
    End With
    
    If ws <> "Nothing found" Then '---> ERROR!
        'some code here…..
    Else
        'some code here
End sub
GSerg
  • 76,472
  • 17
  • 159
  • 346
Yusuf
  • 31
  • 10

1 Answers1

2

You compare different types. ws will returrn Range object if found or Nothing if not found. If I understand what you want right then there should be If Not ws Is Nothing Then ....

ENIAC
  • 813
  • 1
  • 8
  • 19
  • The comparison of different types is not the problem here. `ws.Value` would be [implicitly used](https://stackoverflow.com/a/18051644/11683). – GSerg Sep 06 '20 at 19:26
  • If nothing was found, then `Nothing` will be returned and it does not have `Value` property. – ENIAC Sep 06 '20 at 20:11
  • Thank you lovely people for the solution..variable ws returns nothing so cant be compared to a string... – Yusuf Sep 07 '20 at 06:36