ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamic forms in a macro userform (https://www.excelbanter.com/excel-programming/373723-dynamic-forms-macro-userform.html)

Sjakkie

Dynamic forms in a macro userform
 
At the moment i am trying to dynamically type out a form.
By inputting the id of a user in textbox1 it looks in a1 to a2000 for the id.
So say the value of a16 is returned, i want it to be able to write the value
of b16 in textbox2. the same as if a256 was given b256 would be dynamically
input in textbox2.
Any idea on how i could do this.


Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With Worksheets("customer details").Range("a1:a2000")
Set c = .Find(UserForm1.TextBox1.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
TextBox2.Value = c.value
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub

Bob Phillips

Dynamic forms in a macro userform
 
Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim iRow As Long
With Worksheets("customer details")
On Error Resume Next
iRow = Application.Match(Me.TextBox1.Text, .Range("A1:A2000"), 0)
On Error GoTo 0
If iRow 0 Then
Me.textbox2.Text = .Range("B" & iRow).Value
End If
End With
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Sjakkie" wrote in message
...
At the moment i am trying to dynamically type out a form.
By inputting the id of a user in textbox1 it looks in a1 to a2000 for the

id.
So say the value of a16 is returned, i want it to be able to write the

value
of b16 in textbox2. the same as if a256 was given b256 would be

dynamically
input in textbox2.
Any idea on how i could do this.


Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With Worksheets("customer details").Range("a1:a2000")
Set c = .Find(UserForm1.TextBox1.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
TextBox2.Value = c.value
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub




Die_Another_Day

Dynamic forms in a macro userform
 
TextBox2.Value = c.Offset(,1).Value

HTH

Charles Chickering
Sjakkie wrote:
At the moment i am trying to dynamically type out a form.
By inputting the id of a user in textbox1 it looks in a1 to a2000 for the id.
So say the value of a16 is returned, i want it to be able to write the value
of b16 in textbox2. the same as if a256 was given b256 would be dynamically
input in textbox2.
Any idea on how i could do this.


Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With Worksheets("customer details").Range("a1:a2000")
Set c = .Find(UserForm1.TextBox1.Value, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
TextBox2.Value = c.value
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub




All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com