PDA

View Full Version : [SOLVED:] Type Mismatch



infinity
01-30-2019, 12:14 PM
Hello,

I am trying to look for specific conditions and if those conditions are met I want the selection to move down one row and check for those conditions again and so on. The code I have for this portion is giving me an error that says "Run-Time Error 13 Type Mismatch", I think it may have to do with the "=Today()" portion of it but I am not sure. Can anyone advise? Thank you much!



If ActiveCell.Offset(0, 0).Range("A1") <> "Meeting" And ActiveCell.Offset(0, 10).Range("A1") <> "" Or ActiveCell.Offset(0, 0).Range("A1") = "Meeting" And ActiveCell.Offset(0, 10).Range("A1") <> "" And ActiveCell.Offset(0, 1).Range("A1") >= "=TODAY()" - 1 Then
activecell.offset(1,0).range("A1").Select

Jan Karel Pieterse
01-30-2019, 12:43 PM
I think like so:

If CStr(ActiveCell.Value) <> "Meeting" And CStr(ActiveCell.Offset(0, 10).Value) <> "" Or _
CStr(ActiveCell.Value) = "Meeting" And CStr(ActiveCell.Offset(0, 10).Value) <> "" And CStr(ActiveCell.Offset(0, 1).Value) >= (Date - 1) Then
ActiveCell.Offset(1, 0).Select

infinity
02-01-2019, 05:13 PM
Sorry it took me a couple of days to reply, been working on other things but that worked perfectly, thank you! Would you please tell me what "CStr" is and what it is used for? I have seen this before but don't know how to use it. Thank you so much for your help.

MagPower
02-01-2019, 05:28 PM
Sorry it took me a couple of days to reply, been working on other things but that worked perfectly, thank you! Would you please tell me what "CStr" is and what it is used for? I have seen this before but don't know how to use it. Thank you so much for your help.

Cstr() converts a non-string to a string. For example, Cstr(27) converts that number to "27" .

Jan Karel Pieterse
02-02-2019, 01:49 AM
Apparently, some of your cells contain errors, like #n/a. VBA tries to compare those with your texts and fails because the cell has an error. Cstr first converts the content of the cell to text before comparing it work other text and this avoids the error.