General help
Posted by Matt Walker on July 17, 2001 6:38 AM
Hi, I started this conversation with Ivan earlier today.
It will proberbly make more sense if i start from the begining...
Once apon a time (only kidding!)
I've got a workbook containing 6 sheets. 5 of these sheets contain different type of stock and for ease i have a page contianing a summery of these sheets.
When the user starts excel(97) they are confronted with a userform rather than the workbook. This is designed so that they can edit the sheets in a speific way ie add stock and remove stock by selecting the relavant item form the drop down lists (these items are listed on the totals sheets using the following code)
Private Sub UserForm_Initialize()
Application.Worksheets("Totals").Activate
ComboBox1.ColumnCount = 5
ComboBox1.RowSource = "a5:a48"
ComboBox2.ColumnCount = 5
ComboBox2.RowSource = "a49:a159"
ComboBox3.ColumnCount = 5
ComboBox3.RowSource = "a188:a308"
ComboBox4.ColumnCount = 5
ComboBox4.RowSource = "a308:a320"
ComboBox5.ColumnCount = 5
ComboBox5.RowSource = "a160:a187"
What i'm having trouble with is the code that links these descriptions to their relavant worksheet and cell. i.ve done it this way because the worksheet contains the formula not the macro (which will allow people to edit the formula without messing around with the macro)
I want the user to select item stock x and remove 5 for example and upon closing that particular userform place 5 in the cell on sheet y which affects the total stock of item x.
i hope this isn't to confusing...
As for your questions; i'm using excel 97 and the code that i'm using (at the moment) for the txtboxes is this...
Private Sub TextBox1_Change()
Dim curpos As Double
curpos = TextBox1.SelStart
If Not ValidateNumeric(TextBox1.Text) Then
Beep
MsgBox "Please use numbers only!"
Else
Range("A1") = TextBox1.Value
End If
End Sub
Private Sub TextBox2_Change()
Dim curpos As Double
curpos = TextBox2.SelStart
If Not ValidateNumeric(TextBox2.Text) Then
Beep
MsgBox "Please use numbers only!"
Else
Range("A1") = TextBox1.Value
End If
End Sub
Private Sub TextBox3_Change()
Dim curpos As Double
curpos = TextBox3.SelStart
If Not ValidateNumeric(TextBox3.Text) Then
Beep
MsgBox "Please use numbers only!"
Else
Range("A1") = TextBox1.Value
End If
End Sub
Private Sub TextBox4_Change()
Dim curpos As Double
curpos = TextBox4.SelStart
If Not ValidateNumeric(TextBox4.Text) Then
Beep
MsgBox "Please use numbers only!"
Else
Range("A1") = TextBox1.Value
End If
End Sub
Private Sub TextBox5_Change()
Dim curpos As Double
curpos = TextBox5.SelStart
If Not ValidateNumeric(TextBox5.Text) Then
Beep
MsgBox "Please use numbers only!"
Else
Range("A1") = TextBox1.Value
End If
End Sub
Private Function ValidateNumeric(strText As String) As Boolean
ValidateNumeric = CBool(strText = "" _
Or strText = "-" _
Or strText = "-." _
Or strText = "." _
Or IsNumeric(strText))
End Function
followed by...
Private Sub Userform_close()
Range("sheet1!plantadded") = TextBox1.Value
End Sub
I'm a complete begginer at writing these macros and have compiled this through the (greatly appreciated) comments that you have posted in reply to my pleas.
I hope this casts some light on what i'm trying to achieve.
Thanks again,
M Walker