ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Error type mismatch in writing macro (https://www.excelbanter.com/excel-worksheet-functions/159657-error-type-mismatch-writing-macro.html)

UB

Error type mismatch in writing macro
 
Hi
I have a formula in cell - =IF(J45="","",(J45+181)), where if j45 is blank,
the cell h45 is blank or h45 has a new date, the format of the coloumn "H"
is date.

I my VB code I am using this column to satify a condition and my code is
For rwIndex = 4 To 40
Year(Worksheets("Sheet1").Cells(rwIndex, 12).Value) = Year(Mydate)
Then
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = RGB(0, 0, 255)

I am getting Runtime error '13' - Type Mismatch, because few cells blank,
because of the cell formula IF(J45="","",(J45+181))

Please advise how can I correct the VB code

JE McGimpsey

Error type mismatch in writing macro
 
Your cell isn't blank. It has a formula in it that's returning a null
string as a value... One alternative:

Dim rCell As Range
For Each rCell in Worksheets("Sheet1").Range("L4:L40")
With rCell
If IsDate(.Value) Then
If Year(.Value) = Year(Mydate) Then
.Interior.Color = RGB(0, 0, 255)
End If
End If
End With
Next rCell

In article ,
ub wrote:

Hi
I have a formula in cell - =IF(J45="","",(J45+181)), where if j45 is blank,
the cell h45 is blank or h45 has a new date, the format of the coloumn "H"
is date.

I my VB code I am using this column to satify a condition and my code is
For rwIndex = 4 To 40
Year(Worksheets("Sheet1").Cells(rwIndex, 12).Value) = Year(Mydate)
Then
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = RGB(0, 0, 255)

I am getting Runtime error '13' - Type Mismatch, because few cells blank,
because of the cell formula IF(J45="","",(J45+181))

Please advise how can I correct the VB code


UB

Error type mismatch in writing macro
 
Hi
It worked, Thanks

"JE McGimpsey" wrote:

Your cell isn't blank. It has a formula in it that's returning a null
string as a value... One alternative:

Dim rCell As Range
For Each rCell in Worksheets("Sheet1").Range("L4:L40")
With rCell
If IsDate(.Value) Then
If Year(.Value) = Year(Mydate) Then
.Interior.Color = RGB(0, 0, 255)
End If
End If
End With
Next rCell

In article ,
ub wrote:

Hi
I have a formula in cell - =IF(J45="","",(J45+181)), where if j45 is blank,
the cell h45 is blank or h45 has a new date, the format of the coloumn "H"
is date.

I my VB code I am using this column to satify a condition and my code is
For rwIndex = 4 To 40
Year(Worksheets("Sheet1").Cells(rwIndex, 12).Value) = Year(Mydate)
Then
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = RGB(0, 0, 255)

I am getting Runtime error '13' - Type Mismatch, because few cells blank,
because of the cell formula IF(J45="","",(J45+181))

Please advise how can I correct the VB code




All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com