View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
stevebriz stevebriz is offline
external usenet poster
 
Posts: 195
Default need help w/ macro prompting with info and pasting the info based on user input


Ok try this
Make userform ...I used userform1

add 3 labels (1,2,3)and 2 comboboxes (1 &2)
and 2 command buttons
command button 1 is row move to the next row (below) and gets the
entrys.
command buton 2 enter the data to sheet1
paste the code below.

assumptions:
on sheet 2 the amount is column 3 (C) , the Dacct in col 4 (D) and
'status' (good/bad) in col 6 (F). and the first entry is on row 3

The data output goes in sheet 1

previous year row 10

jan this year starts at row 12 and so on down
15000 data goes in column 3 (C)
16000 data goes inis column 4 (D)
17000 data goes in column 5 (E)

Numbers are added as you requested.
Anyway code is below
If you have any questions let me know
-------------------------------------------------


Private Sub CommandButton1_Click()
Cells(ActiveCell.Row + 1, 3).Select ' moves to the next entry
Call refresh ' get data from sheet 2

End Sub

Private Sub CommandButton2_Click()
' write data to sheet 1 for current entry
Call populate
End Sub



Sub refresh()
Sheet2.Activate
Cells(ActiveCell.Row, 3).Select
Label1.Caption = ActiveCell.Value
Label2.Caption = ActiveCell.Offset(0, 1).Value
Label3.Caption = ActiveCell.Offset(0, 3).Value
With ComboBox1 ' populate month combo box
..Clear
..AddItem "Jan"
..AddItem "Feb"
..AddItem "Mar"
..AddItem "Apr"
..AddItem "May"
..AddItem "Jun"
..AddItem "Jul"
..AddItem "Aug"
..AddItem "Sep"
..AddItem "Oct"
..AddItem "Nov"
..AddItem "Dec"
..ListIndex = 0
End With
With ComboBox2
..Clear
..AddItem "Current Year"
..AddItem "Previous Year"
..ListIndex = 0
End With
End Sub
Sub populate()

If ComboBox2.ListIndex = 1 Then ' is the entry for the previous year
If UserForm1.Label2.Caption = "15000" Then Sheet1.Cells(10,
3).Value = Sheet1.Cells(10, 3).Value + Val(UserForm1.Label1.Caption)
If UserForm1.Label2.Caption = "16000" Then Sheet1.Cells(10,
4).Value = Sheet1.Cells(10, 4).Value + Val(UserForm1.Label1.Caption)
If UserForm1.Label2.Caption = "17000" Then Sheet1.Cells(10,
5).Value = Sheet1.Cells(10, 5).Value + Val(UserForm1.Label1.Caption)
Else
' for the current year

Dim i As Integer
i = 12 + ComboBox1.ListIndex ' for the month

If UserForm1.Label2.Caption = "15000" Then Sheet1.Cells(i,
3).Value = Sheet1.Cells(i, 3).Value + Val(UserForm1.Label1.Caption)
If UserForm1.Label2.Caption = "16000" Then Sheet1.Cells(i,
4).Value = Sheet1.Cells(i, 4).Value + Val(UserForm1.Label1.Caption)
If UserForm1.Label2.Caption = "17000" Then Sheet1.Cells(i,
5).Value = Sheet1.Cells(i, 5).Value + Val(UserForm1.Label1.Caption)

End If
End Sub
Private Sub UserForm_Initialize()
Sheet2.Activate
Sheet2.Cells(3, 3).Select ' starts at the amount in the third row, 3rd
column
Call refresh

End Sub