mismatch error when populate date in adjacent cell based on word in another

leap out

Active Member
Joined
Dec 4, 2020
Messages
271
Office Version
  1. 2016
  2. 2010
Hello
I search for way to fix mismatch error in this line
VBA Code:
If Range("E2:E" & I).Value = "PAID"
after populate date in adjacent cells in column F if the cells in column E contain "PAID" will show the error !
I use this
VBA Code:
Dim I As Long, LR As Long
For I = 2 To LR
If Range("B2:B" & I).Interior.ColorIndex = xlNone Then Range("E2:E" & I) = "PAID"
If Range("E2:E" & I).Value = "PAID" Then Range("F2:F" & I) = Date
Next I
but I'm not sure where is my bad !
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Where exactly are you defining the value of "LR"?
If you have not defined it anywhere, it has a value of 0, so you are literally telling your loop to go:
Excel Formula:
For I = 2 to 0
and row 0 is not possible and will result in an error.

In code like you have posted above, people will typically calculate and set LR before using it in a loop, i.e.
VBA Code:
Dim I As Long, LR As Long
LR = Cells(Rows.Count, "F").End(xlUp).Row
For I = 2 To LR
    If Range("B2:B" & I).Interior.ColorIndex = xlNone Then Range("E2:E" & I) = "PAID"
    If Range("E2:E" & I).Value = "PAID" Then Range("F2:F" & I) = Date
Next I
 
Upvote 0
Sorry, I misread your original question. It looks like you should be using column E to find the last row with data instead of column F:
VBA Code:
Dim I As Long, LR As Long
LR = Cells(Rows.Count, "E").End(xlUp).Row
For I = 2 To LR
    If Range("B2:B" & I).Interior.ColorIndex = xlNone Then Range("E2:E" & I) = "PAID"
    If Range("E2:E" & I).Value = "PAID" Then Range("F2:F" & I) = Date
Next I
 
Upvote 0
it shows the same error and in the same line as I have ever mentioned.:(
 
Upvote 0
The if statement is not happy with trying to evaluate a range of cells.

VBA Code:
Sub test()

Dim I As Long, LR As Long
LR = Cells(Rows.Count, "E").End(xlUp).Row
For I = 2 To LR
    If Range("B" & I).Interior.ColorIndex = xlNone Then Range("E" & I) = "PAID"
    If Range("E" & I).Value = "PAID" Then Range("F" & I) = Date
Next I

End Sub
 
Upvote 0
Solution
I don't understand what you try to say !
I'm surprised from the problem as bold ranges , I no know why !
Rich (BB code):
If Range("B2:B" & I).Interior.ColorIndex = xlNone Then Range("E2:E" & I) = "PAID"
    If Range("E2:E" & I).Value = "PAID" Then Range("F2:F" & I) = Date
I would inform you also when change as bold red
Rich (BB code):
Range("E2:E" & I).Text= "PAID"
also works perfectly
anyway your updating has solved my problem.(y)
thank you so much .:)
 
Last edited:
Upvote 0
Interesting.
See if this helps:

20230926 VBA If Range of cells leap out.xlsm
ABC
2ExpressionNo of CellsResult
3Range("E2").Value = "PAID"1Works
4Range("E2:E2").Value = "PAID"1Works
5Range("E2:E3").Value = "PAID"2Error 13 Type mismatch
6Range("E2:E4").Value = "PAID"3Error 13 Type mismatch
7Range("E2:E4").Text = "PAID"3The Text part only returns a value if all 3 cells have the exact same value, otherwise returns null
Notes
 
Upvote 0
case 1 doesn't show any thing
case 2: case 4 will show error
final case I don't understand it !
f all 3 cells have the exact same value
you're talking about cells in column C,D,E ?
 
Upvote 0
you're talking about cells in column C,D,E ?
No the If statement was using a range of E2:E & I.
So below is what your Text option returns when I =4 and the Range is Range("E2:E4").
Unless all 3 Cells in the Range E2:E4 are the same, the Text property returns Null.

1695729001694.png
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,307
Members
449,151
Latest member
JOOJ

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top