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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,696
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
At which line? There are two with lngRed being used.
 

markw1804

New Member
Joined
Nov 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
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)
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,696
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

Does it help if you use:

Code:
lngRed = VBA.RGB(255, 0, 0)
 
Solution

markw1804

New Member
Joined
Nov 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Thank you! Its not erroring now, but its also not coloring the textbox red :) Getting closer
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,696
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Are you sure the location box contains G3A? (note your test is case sensitive)
 

markw1804

New Member
Joined
Nov 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,129,527
Messages
5,636,834
Members
416,945
Latest member
Himu

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
Top