PDA

View Full Version : VBA PASSING VARIABLE



PEREZJ
02-04-2013, 06:18 PM
nline should increment by 1 every time I press the button, but it changes to 0. I'm have trouble passing the variable and defining them, please help.

Private Sub ComboBox1_Change()
End Sub

Private Sub ComboBox2_Change()
End Sub

Private Sub CommandButton1_Click()
Dim nline As Integer
nline = nline + 1
Range("C1").Value = ComboBox1.Text
Cells(nline, 4).Value = Now()
End Sub

Private Sub TextBox1_Change()
End Sub

Private Sub nline_Change()
End Sub

Private Sub UserForm_Click()
End Sub

Private Sub UserForm_Initialize()
Me.ComboBox1.List = Worksheets("setup").Range("A1:A3").Value
Me.ComboBox2.List = Worksheets("setup").Range("B1:B3").Value
End Sub

Dave
02-06-2013, 10:26 AM
Take this out of the command button code and place at the top of the code module. Dave

Dim nline As Integer

Bob Phillips
02-06-2013, 03:42 PM
Private Sub CommandButton1_Click()
Static nline As Integer
nline = nline + 1
Range("C1").Value = ComboBox1.Text
Cells(nline, 4).Value = Now()
End Sub

Dave
02-06-2013, 08:26 PM
Thanks xld for the learning re. static. I had not seen this before. Dave