UserForm Button Data entry from multiple Choices

Dan Swartz

New Member
Joined
Apr 17, 2020
Messages
18
Office Version
  1. 365
Platform
  1. Windows
NEED:
I need the ability that when an Item number is entered into a range of cells, "B2:B25", that immediatly a message box pops up where the operator MUST choose and color to continue. When selecting the color, it will enter that value in the adjacent cell. For example. if I enter the item number for Flooring in B5, the "Select Color" Userform pops up and if I select "Green", it will enter "Green" in C5.

I will use formulas to pull all other values. just need it to enter the chosen color in column C.

I have the formula and UseForm working......Kinda. :)

In this example, I just entered 001975 in B5 and the "Select Color" user form pops up asking for the color code. if I click any color, it should enter the color in C5.

1631713424028.png


My problem: This will work as long as I start at B2 and work row by row downward. However, if I start at B15 or so and work up, the results are completly wrong. It puts the value in Column C in very random spots.

The Color Picker also needs locked to a range "B2:B25". anything outside of B2:B25, I don't want it to pop up.

the code is close. but I can't seem to lock the range and make it work in any direction.

This is my code to call the UserForm

Option Explicit
__________________________________________________________________________
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ColorRange As Range

Set ColorRange = Range(Cells(2, "B"), Cells(Rows.Count, "B").End(xlUp))

If Target.Cells.Count > 1 Then Exit Sub

If Not Application.Intersect(Target, ColorRange) Is Nothing Then
ColorPickerUF.Show
End If

End Sub

____________________________________________________________________________

This is my code for each Color Button.

Private Sub BlueCB_Click()
With ActiveSheet
.Cells(Rows.Count, "b").End(xlUp).Offset(0, 1).Value = BlueCB.Caption
ColorPickerUF.Hide
End With
End Sub

Private Sub GreenCB_Click()
With ActiveSheet
.Cells(Rows.Count, "b").End(xlUp).Offset(0, 1).Value = GreenCB.Caption
ColorPickerUF.Hide
End With
End Sub


Private Sub YellowCB_Click()
With ActiveSheet
.Cells(Rows.Count, "b").End(xlUp).Offset(0, 1).Value = YellowCB.Caption
ColorPickerUF.Hide
End With
End Sub
Private Sub RedCB_Click()
With ActiveSheet
.Cells(Rows.Count, "b").End(xlUp).Offset(0, 1).Value = RedCB.Caption
ColorPickerUF.Hide
End With
End Sub
Private Sub PurpleCB_Click()
With ActiveSheet
.Cells(Rows.Count, "B").End(xlUp).Offset(0, 1).Value = PurpleCB.Caption
ColorPickerUF.Hide
End With
End Sub

Private Sub OrangeCB_Click()
With ActiveSheet
.Cells(Rows.Count, "b").End(xlUp).Offset(0, 1).Value = OrangeCB.Caption
ColorPickerUF.Hide
End With
End Sub


I would upload a sample sheet, but can't figure out how too.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,209
Your form needs to know what cell is involved. If you change the calling code to
VBA Code:
' in Worksheet_Change event

If Not Application.Intersect(Target, ColorRange) Is Nothing Then
    ColorPickerUF.Tag = Target.Address(,,,True)
    ColorPickerUF.Show
End If
and your button codes to
VBA Code:
' in userform code module

Private Sub OrangeCB_Click()
    Range(Me.Tag).Offset(0,1).Value = OrangeCB.Caption
    ColorPickerUF.Hide
End Sub
that should work.
 
Solution

Dan Swartz

New Member
Joined
Apr 17, 2020
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Your form needs to know what cell is involved. If you change the calling code to
VBA Code:
' in Worksheet_Change event

If Not Application.Intersect(Target, ColorRange) Is Nothing Then
    ColorPickerUF.Tag = Target.Address(,,,True)
    ColorPickerUF.Show
End If
and your button codes to
VBA Code:
' in userform code module

Private Sub OrangeCB_Click()
    Range(Me.Tag).Offset(0,1).Value = OrangeCB.Caption
    ColorPickerUF.Hide
End Sub
that should work.
I'll Give this a try! thanks. I'll let you know if that works.
 

Dan Swartz

New Member
Joined
Apr 17, 2020
Messages
18
Office Version
  1. 365
Platform
  1. Windows
I'll Give this a try! thanks. I'll let you know if that works.
Mike, this is worked perfectly! thank you! I wouldn't have got that! One More question. In all of this. I want to lock this to only work in a range of Cells. B2:B25.

I'm guessing it has to do with my Set Color Range code, but I could only get it to work this way.

Set ColorRange = Range(Cells(2, "B"), Cells(Rows.Count, "B").End(xlUp))
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,428
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

To limit the range you can use
VBA Code:
Set ColorRange = Range("B2:B25")
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,428
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

The rest of what line?
 

Dan Swartz

New Member
Joined
Apr 17, 2020
Messages
18
Office Version
  1. 365
Platform
  1. Windows
The rest of what line?
Set ColorRange = Range(Cells(2, "B"), Cells(Rows.Count, "B").End(xlUp))

where do you put the range? No matter where I put it, it gives me an error. I'm assuming I have something wrong.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,428
Office Version
  1. 365
Platform
  1. Windows
Just replace that line with the code I suggested.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,571
Messages
5,838,160
Members
430,532
Latest member
Clod

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