[RESOLVED] How to check if a subspring is within a string?
Hi, I need know if the caption of a checkbox is within the name of a sheet.
I tried this, but it's not working, because "Else" aways happens, to all sheets(k), even in not having the text of the checkbox in the name of the sheet.
Code:
If CheckBox2 = True Then
j=0
For k = 1 To Sheets.Count
If InStr(1, Sheets(k).Name, checkbox2.caption, 1) = 0 And InStr(1, Sheets(k).Name, checkbox1.text, 1) = Null Then
Else
Sheets_I_Need(j) = k
j = j + 1
End If
Next k
End If
What could I do?
Re: How to check if a subspring is within a string?
I tried just
Code:
InStr(Sheets(k).Name, checkbox2.caption) = 0 Then
and I guess it's ok now,
though it doesn't check the case "Null", it already helps a little
Re: How to check if a subspring is within a string?
you can not check for null using AND
you must check for null first, then the other criteria if not null
Re: How to check if a subspring is within a string?
Oh, right, I should use "Or", not "And" in that case.
Thanks
Re: [RESOLVED] How to check if a subspring is within a string?
Quote:
I should use "Or", not "And" in that case.
same applies, as it always evaluates both conditions, in cases it is null, evaluating the other condition will error
must be done like
Code:
if not isnull(something) then
if something = x then somethingelse = y
end if