Change Interior.Color VBA

ExcelNooberino

New Member
Joined
Jan 2, 2019
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
Hello to you all! So, I'm working on this new UserForm to add some new entrys of info I need to keep track of the data. Basically it has some textboxes and a couple of comboboxes and I'm struggling to change the cell color of the last field (combobox) in the database. It only has two variables, "Inbound" and "Outbound" and I just want to do the typical color assignment with the green color for Inbound and red for Outbound. So far I have this:

Private Sub submitBtn_Click()

erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row


Cells(erow, 1) = DTPicker.Value
Cells(erow, 2) = comboRef.Value
Cells(erow, 4) = textQuantity.Text & " KG"
Cells(erow, 5) = textValue.Text
Cells(erow, 6) = textCarrier.Text
Cells(erow, 7) = textCost.Text
Cells(erow, 8) = textLTPR.Text
Cells(erow, 9) = comboBound.Value


If Cells(erow, 2) = "MR0006AAAA0" Then
Cells(erow, 3) = "PURGAS PP"
End If


If Cells(erow, 2) = "MR0007AAAA0" Then
Cells(erow, 3) = "SCRAP PP"
End If


If Cells(erow, 2) = "MR5015AAAA0" Then
Cells(erow, 3) = "HXCA PP MOIDO/JITOS"
End If


If Cells(erow, 2) = "MR5002AAAA0" Then
Cells(erow, 3) = "RECICLADO TICONA"
End If


MsgBox "New entry added successfully!", vbInformation, "New entry added"


myForm.Hide


End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Please provide some more information.
I don't understand what you try to achieve. Do want to change a cell color?
I this is the case - easiest way is to use the macro recorder, change the colors manually the way you want them and then inspect the recorded code and adjust it to your needs.

it would be something like:
Code:
If combobound.value="inbound" then cells(erow,9).Color = vbGreen else cells(erow,9).Color = vbRed
 
Upvote 0
It would be like this:

Code:
If Cells(erow, 9) = "Inbound" Then Cells(erow, 9).Interior.Color = vbGreen
If Cells(erow, 9) = "Outbound" Then Cells(erow, 9).Interior.Color = vbRed
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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