Vba help colouring cells after data input

mattless1

Board Regular
Joined
Apr 1, 2011
Messages
102
Hi, can anyone help me?

I am working on a user form with four txt boxes that enters information into row 1 and A,B,C & D. The next time i enter info into the workbook it enters it into the next empty row. This is what what i would like to do if possible. It is to make the data cells i've just filled in go red. Is there any vba code i could add to my user form that makes the data cells turn red after i have entered in the data.

Many thanks if you can help.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,
I do this using basically the idea beneath the "pseudo code" below


Code:
Sub tbTextBox1_Change()
VarTestForChange = Sheets("Product").Cells(4, 3)  'C4
VarEnterAmount = tbTextBox1
If Not VarTestForChange = VarEnterAmount Then
    Sheets("Product").Cells(writeRow, 4) = tbTextBox1
        Range("C4").Select
    With Selection.Interior
        .ColorIndex = 6  'Red
        .Pattern = xlSolid
    End With
End Sub

This code would sit in the Text Box Click or change event or could be placed in the "Save Routine"

Regards,

Alan
 
Upvote 0
Many thanks for the reply. I have tried placing into a txt box and as a commandbutton, but with no luck. I'm sure it's something i'm doing. Here is a copy of my code for the userform maybe it how i'm placing it.

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for a part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtloc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value

'clear the data
Me.txtPart.Value = ""
Me.txtloc.Value = ""
Me.txtDate.Value = ""
Me.txtQty.Value = ""
Me.txtPart.SetFocus

End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Many thanks
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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