PDA

View Full Version : Userform to Find Cell from ComboBox Value and write to Adjacent Cells



Silver
05-13-2015, 10:33 AM
PART 1

Agents update their days work in Production sheet. Since the agents work on 10 categories
it becomes time consuming to scroll through the sheet to update their time and counts.

Came across a userform on the net.

Pretty much what I'm looking for, though needs few additions and changes.

A brief info of what it does -

Using data from combobox to find the cell on the worksheet
and write to a specific adjacent cell.

Worksheet name is Jan
ComboBox1 Name is cmbDate
ComboBox2 Name is cmbCat
TextBox name is txtAmount
CommandButton1

Using the date value from cmbDate, find this text in Row A of worksheet Jan
and write the Value of txtAmount in a cell adjacent to the date and under the cell
equal to the cmbCat value when the CommandButton1 is pressed.

Attached is the worksheet (Household Planner)

Have attached 2nd worksheet which is a copy of the original with few changes to it
(Production Sheet - where I need the changes)

What I'm looking for -

ComboBox1 Name is cmbDate
ComboBox2 Name is cmbCat
I need 2 textboxes - txtTime and txtCount
CommandButton1

When clicked on commandbutton1 it should do what is explained as above
(highlighted in Bold), except, the data entered in the 2 textboxes should reflect under the columns Time and Counts.

Also need a Goto button - with datas selected in cmbDate and cmbCat
when clicked on Goto button it should take me to the relevant cells.

Below is a snapshot

13363

cmbDate - 2
cmbCat - Alcohol/Cigaretes

with above selection made it should take me to the Time column under
Category Alcohol/Cigaretes of Date 2 (Date format may change to 02-May-15)

PART 2

Would like to know if a summary can be generated of all the categories the agents has worked on including Time and Counts, based on dates selected.

SamT
05-13-2015, 06:43 PM
You must be more clear in your explanation.

I have edited your original post by adding questions to it. Please read and answer.

Note that there is a profound difference between a Worksheet and a Workbook.
For example, you have a workbook named like a Worksheet, "Production Sheet.xlsm" that does not have a Worksheet named "Production" in it. This is confusing unless your explanation is very clear.

Are you asking us to help you make the form and write the code?
Are you asking use to give you the completed code base that will do all the work for you?

Silver
05-14-2015, 02:01 AM
Apologies, this is My first time dealing with a Userform.

Below is the code which I got from the net


Private Sub cmdAdd_Click()Dim iRow As Long, iCol As Long


If cmbDate = "" Then
MsgBox "please select a date"
cmbDate.SetFocus
Exit Sub
End If
If cmbCat = "" Then
MsgBox "please select a category"
cmbCat.SetFocus
Exit Sub
End If
If txtAmount = "" Then
MsgBox "please enter then amount"
txtAmount.SetFocus
Exit Sub
End If


With ActiveSheet
iRow = .Range("A:A").Find(cmbDate.Value, LookIn:=xlValues, LookAt:=xlWhole).Row
iCol = .Range("3:3").Find(cmbCat.Value, LookIn:=xlValues, LookAt:=xlWhole).Column
.Cells(iRow, iCol) = .Cells(iRow, iCol) + txtAmount
End With


'clear the data
cmbDate.Value = ""
cmbCat.Value = ""
txtAmount.Value = ""
cmbDate.SetFocus


End Sub


Private Sub cmdDone_Click()
Unload Me
End Sub


Private Sub UserForm_Initialize()
Dim cItem As Range


Dim ws As Worksheet


Set ws = ActiveSheet
For Each cItem In ws.Range("3:3").SpecialCells(xlConstants).Offset(, 0)
With Me.cmbCat
If cItem <> "" And cItem <> "Total" Then .AddItem cItem.Value
End With
Next cItem


For Each cItem In ws.Range("A:A").SpecialCells(xlConstants, xlNumbers)
With Me.cmbDate
.AddItem cItem.Value
End With
Next cItem


End Sub


What the above code do -

Using the date value from cmbDate, find this text in Row A of worksheet Simon
and write the Value of txtAmount in a cell adjacent to the date and under the cell
equal to the cmbCat value when the CommandButton1 is pressed.

Refer attached workbook Household Planner (Original post) to get better understanding of above explanation

A bit of studying helped me to make changes to the existing userform
(Have attached workbook with the changes)

I have added below buttons -

Goto (command button)
Time (textbox)
Counts (textbox)

What I want is to add codes for the above 3 buttons to the above mentioned code

For Goto refer to explanation from my original post

For textboxes Time and Counts the code should do the following -

Agents will select data from both the combo boxes and manually enter data into both the
text boxes.

When command button Enter is clicked the data entered in both the text boxes should reflect
under the headings Time and Counts column in the excel sheet and also under the correct
category and for the said date

Below snapshot describes above explanaion -

13380

Edit : It would be helpful if you can attach the finished work

Silver
05-14-2015, 09:41 PM
Any help people