View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Data Entry-Cell selection

This assumes the worksheet name is "Sheet1". Change the name in the code to
suit. Also assumed is that there is an Apply button on the UF that pastes the
sales data to the appropriate cell. The name of this button (CommandButton)
is cbApply and its Enable property is set to False.

Paste to the UF code module. Done in a hurry and minimal testing.

Dim ws As Worksheet

Private Sub cboMonth_Change()
cbApply.Enabled = EnableApplyBtn
End Sub
Private Sub cboProduct_Change()
cbApply.Enabled = EnableApplyBtn
End Sub
Private Sub txtSales_Change()
cbApply.Enabled = EnableApplyBtn
End Sub

Private Sub UserForm_Activate()
Dim r As Range, r2 As Range
Dim i As Integer

Set ws = Sheets("Sheet1") 'Change ws name to suit
Set r = ws.Range(ws.Cells(2, 1), ws.Cells(2, 1).End(xlDown))
Set r2 = ws.Range("B1:M1")
cboProduct.RowSource = r.Address
For i = 1 To 12
cboMonth.AddItem r2(i)
Next
End Sub

Private Sub cbApply_Click()
Dim m As String, p As String, s As String
Dim r As Range, c As Range, cc As Range

m = cboMonth.Value
p = cboProduct.Value
s = txtSales.Value
Set r = ws.UsedRange
Set c = r.Find(p)
Set cc = r.Find(m)
r.Cells(c.Row, cc.Column) = s
End Sub

Private Function EnableApplyBtn() As Boolean
EnableApplyBtn = (Len(cboProduct) 0 And Len(cboMonth) 0 And
Len(txtSales) 0)
End Function

Regards,
Greg


"P.Jaimal" wrote:

Hi ,
My knowledge about excel programming is very limited. I have a
sheet with months in the first row. The first column contains names of
Products. The intervening grid contains the sales of these items for
these months.

A B C D E
1 APR MAY JUNE JULY
2 PRODUCT 1
3 PRODUCT 2
4 PRODUCT 3
5 PRODUCT 4

My userform has comboboxes "cboMonth" and "cboProduct".A text
box "txtSales".I would like to enter data into the sheet depending
on the selections of the two comboboxes.Example: if
cboMonth.Value="MAY" AND cboProduct.Value ="PRODUCT 3" then the
data from txtSales should get copied to the cell "C4".
I am unable to link these using code.My sheet is very long with many
products(and therefore many Rows).Hence a data entry form is very much
useful .
Please help.

P.Jaimal