Results 1 to 3 of 3

Thread: If statement shows objected required?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    258

    If statement shows objected required?

    When debug it, it shows error "objected required", here is the code
    Code:
     If InStr(1, Criteria, R, vbTextCompare) > 0 And Not R Is Nothing Then
    I try several ways to figure out how to compare "" and null. when use IsNull, R="", IsNull(R)will be true, but I hope to when R="", it will return false, so how to use the function?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    258

    Re: If statement shows objected required?

    I use R = Cells(row, "AK"), there is nothing in this cell, but debug it, it shows R=" ", so how to do it in the if conditions use null or nothing ?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: If statement shows objected required?

    R = Cells(row, "AK")
    if R is dimensioned as a range an error should occur here, else in this case R would be a variant, which is not an object
    try like
    Code:
    set R = Cells(row, "AK")
    in this case R would be a range object

    If InStr(1, Criteria, R, vbTextCompare) > 0 And Not R Is Nothing Then
    if r is nothing an error would occur, when trying to evaluate the first criteria, you must do like
    Code:
    if not R is nothing then
            If InStr(1, Criteria, R, vbTextCompare) > 0  Then
    in this case if R is nothing the other criteria would not be evaluated
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width