I am working on a worksheet_change where there are a number of select cells that I need to Ucase and a couple of cells that I need to ProperCase. Please see the code below. I put in each cell reference one by one, to see if there was an issue with one of the cells, because I just can't seem to get past this run-time error, and everything ran without issue. There are 2 cells that have a mix of numbers and letters and the rest have only letters.
I added the following code. Please don't mind all the notes. I am not fluent in VBA so this saves me time when I have to go back and debug.
After I added the code above, I get run-time error 13 that says type mismatch. The following code is highlighted.
What am I doing wrong? From what I read on the good old internet, it says I must be trying to convert something that isn't text, which I guess isn't compatible with the UCase function.
First I removed the 2 cells that have numbers and it still gives me the same error.
Then I removed the select case coding and I still get the same error.
Then I removed the ProperCase coding and I still get the same error.
I ended up putting everything (ProperCase and select case) back in EXCEPT the Ucase and I no longer get the run-time error. By process of elimination, there is something not running correctly with my Ucase coding or there is something in my worksheet that is not compatible with Ucase maybe? I do not have any conditional formatting or other macros or VBA coding that could be interfering.
Any suggestions?
Code:
If Not Intersect(Target, Union(Range("AI13:AI14,H17,P17:P19,R16,T16:T19,AA17:AA18,AI16,G21,G24,S20:S22,AA20:AA22,AH21:AH25" _
), Range( _
"AP21:AP24,AK28:AL28,AK30:AL30,AK32:AL32,AP28:AP31,AX32,AY44,AP45:AP47,AY48,AP49:AP54,AP56:AP60,AY64,AP65,AU65,C38:C65" _
), Range( _
"V38:V65,W66,C67:C70,AJ67:AJ68,AV69,Y71:AW74,C72:C79,L80,R80,C81:C82,C86:C94,K86:K94,AD77,AC77:AD80,AK77:AL80,AS77:AT80" _
), Range( _
"G96,G98,Y86,AG88,AG90:AG92,AG95,AG97:AG98,AO87:AU99" _
))) Is Nothing Then
'
Application.ScreenUpdating = False
Application.EnableEvents = False
'
Target = UCase(Target)
'
Application.ScreenUpdating = True
Application.EnableEvents = True
'
End If
'
If Not Intersect(Target, Range("J13,H37")) Is Nothing Then
'
Application.ScreenUpdating = False
Application.EnableEvents = False
'
Target = StrConv(Target, vbProperCase)
'
Application.ScreenUpdating = True
Application.EnableEvents = True
'
End If
I added the following code. Please don't mind all the notes. I am not fluent in VBA so this saves me time when I have to go back and debug.
Code:
'A: MCD--> If the resident does not have MCD [AI14=NO], then subsequent cell is highlighted and the font color is changed to bold red.
'
Select Case Range("AI14").Value
Case "NO"
Application.ScreenUpdating = False
Application.EnableEvents = False
Range("AI14").Interior.Color = RGB(255, 255, 0)
Range("AI14").Font.Color = RGB(255, 0, 0)
Range("AI14").Font.Bold = True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Select
'
'A: MCD-->If the subsequent cell is blank[AI14=""], then the cell fill matches and font is normal.
'
Select Case Range("AI14").Value
Case ""
Application.ScreenUpdating = False
Application.EnableEvents = False
Range("AI14").Interior.Color = RGB(226, 239, 218)
Range("AI14").Font.Color = RGB(0, 112, 192)
Range("AI14").Font.Bold = False
Application.ScreenUpdating = True
Application.EnableEvents = True
End Select
'
'A: MCD-->If the subsequent cell has a MCD number, then the cell fill matches and font is normal.
'
Select Case Range("AI14").Value
Case Is <> "NO"
Application.ScreenUpdating = False
Application.EnableEvents = False
Range("AI14").Interior.Color = RGB(226, 239, 218)
Range("AI14").Font.Color = RGB(0, 112, 192)
Range("AI14").Font.Bold = False
Application.ScreenUpdating = True
Application.EnableEvents = True
End Select
After I added the code above, I get run-time error 13 that says type mismatch. The following code is highlighted.
Code:
Target = UCase(Target)
What am I doing wrong? From what I read on the good old internet, it says I must be trying to convert something that isn't text, which I guess isn't compatible with the UCase function.
First I removed the 2 cells that have numbers and it still gives me the same error.
Then I removed the select case coding and I still get the same error.
Then I removed the ProperCase coding and I still get the same error.
I ended up putting everything (ProperCase and select case) back in EXCEPT the Ucase and I no longer get the run-time error. By process of elimination, there is something not running correctly with my Ucase coding or there is something in my worksheet that is not compatible with Ucase maybe? I do not have any conditional formatting or other macros or VBA coding that could be interfering.
Any suggestions?