Type mismatch 13 setting Backcolor using RGB

markw1804

New Member
Joined
Nov 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,
Im sure this is staring me in the face, I have the following simple piece of code that if the stock location of the item matches it colours the textbox red.
The item number is pulled from a combobox and it populates all the information but I have a map of the stock locations on a userform made up of textboxes with names that match the stock location.
If they get a match the box colours red.
Im getting type mismatch at the lngRed line? I have used this before? Cant work it out.
Any pointer would be happily accepted.


P
VBA Code:
rivate Sub cmbItemNo_Change()
Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Stock")
        
    Me.txtLocation.Value = ws.Range("D" & Me.cmbItemNo.ListIndex + 3).Value
    Me.txtPallet.Value = ws.Range("C" & Me.cmbItemNo.ListIndex + 3).Value
    Me.txtRack.Value = Left(Me.txtLocation.Value, 1)
    Me.txtLevel.Value = Mid(Me.txtLocation.Value, 2, 1)
    Me.txtCol.Value = Right(Me.txtLocation.Value, 1)
     

Dim lngRed As Long
lngRed = RGB(255, 0, 0)

If Me.txtLocation.Value = "G3A" Then
Me.G3A.BackColor = lngRed
End If

   
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
At which line? There are two with lngRed being used.
 
Upvote 0
Im getting the same error at the same place with that?
Apologies the debugger was throwing out at the following line...

VBA Code:
lngRed = RGB(255, 0, 0)
 
Upvote 0
Does it help if you use:

Code:
lngRed = VBA.RGB(255, 0, 0)
 
Upvote 0
Solution
Thank you! Its not erroring now, but its also not coloring the textbox red :) Getting closer
 
Upvote 0
Are you sure the location box contains G3A? (note your test is case sensitive)
 
Upvote 0
Working now, Thank you for all your help, the textbox name had reverted to default??? Changed it back and all good now.
I appreciate the help!!! Thank you!
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,927
Members
448,533
Latest member
thietbibeboiwasaco

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