Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default userform and VBA code

I'm starting to build a user form in excel and need a push start. I
have an excel file that contains about 15 columns of data with about
1600 rows. The table is a list of all active employees, their
location, department ID, their RC, superviors's name...etc. I'd like
to create a userform that can be used to list a given employee and all
the items from their row of data.

So to get me started can someone show me an example of vba code that
will be used in a text box, for example, as a search...ie the user
enters an employee ID number (which is in column A) and then other
text boxes brings in the location, rc and so on in other text boxes
placed on the form. If I can see some example code to pull in the
value from Column A and then Column B that would be a great start for
me. Thanks a ton!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default userform and VBA code

I would suggest that you get all employee ID and load these into a combobox.
When a selection is made from there, build an array of records for that
employee and provide back and forward buttons for going through this array,
and retreive those details and display them.

You can get all unique employees like so

With Worksheets("Data")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
sId = ""
For i = 2 To iLastRow
if .Cells(i,"A").Value < sId Then
sId = .Cells(i,"A").Value
Me.ComboBox1.AddItem .Cells(i,"A").Value
End If
Next I
Me.ComboBox1.ListIndex = -1
End With

You can then load an array like this, and prime it like so

ReDim aryRows(1 To 1)
iRow = 1

With Worksheets("Data")
For i = 2 To iLastRow
If .Cells(i, "A").Value = 1 Then 'Me.Combobox1.Value Then
ReDim Preserve aryRows(1 To iRow)
aryRows(iRow) = i
iRow = iRow + 1
End If
Next i
End With
iRow = 0

and then retrieve like so

Private Sub cmdNext_Click()
With Worksheets("Data")
If iRow = UBound(aryRows) Then
MsgBox "no more"
Else
iRow = iRow + 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub

Private Sub cmdPrevious_Click()
With Worksheets("Data")
If iRow <=1 Then
MsgBox "no more"
Else
iRow = iRow - 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub




--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
ups.com...
I'm starting to build a user form in excel and need a push start. I
have an excel file that contains about 15 columns of data with about
1600 rows. The table is a list of all active employees, their
location, department ID, their RC, superviors's name...etc. I'd like
to create a userform that can be used to list a given employee and all
the items from their row of data.

So to get me started can someone show me an example of vba code that
will be used in a text box, for example, as a search...ie the user
enters an employee ID number (which is in column A) and then other
text boxes brings in the location, rc and so on in other text boxes
placed on the form. If I can see some example code to pull in the
value from Column A and then Column B that would be a great start for
me. Thanks a ton!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default userform and VBA code

On Jul 11, 11:32 am, "Bob Phillips" wrote:
I would suggest that you get all employee ID and load these into a combobox.
When a selection is made from there, build an array of records for that
employee and provide back and forward buttons for going through this array,
and retreive those details and display them.

You can get all unique employees like so

With Worksheets("Data")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
sId = ""
For i = 2 To iLastRow
if .Cells(i,"A").Value < sId Then
sId = .Cells(i,"A").Value
Me.ComboBox1.AddItem .Cells(i,"A").Value
End If
Next I
Me.ComboBox1.ListIndex = -1
End With

You can then load an array like this, and prime it like so

ReDim aryRows(1 To 1)
iRow = 1

With Worksheets("Data")
For i = 2 To iLastRow
If .Cells(i, "A").Value = 1 Then 'Me.Combobox1.Value Then
ReDim Preserve aryRows(1 To iRow)
aryRows(iRow) = i
iRow = iRow + 1
End If
Next i
End With
iRow = 0

and then retrieve like so

Private Sub cmdNext_Click()
With Worksheets("Data")
If iRow = UBound(aryRows) Then
MsgBox "no more"
Else
iRow = iRow + 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub

Private Sub cmdPrevious_Click()
With Worksheets("Data")
If iRow <=1 Then
MsgBox "no more"
Else
iRow = iRow - 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message

ups.com...



I'm starting to build a user form in excel and need a push start. I
have an excel file that contains about 15 columns of data with about
1600 rows. The table is a list of all active employees, their
location, department ID, their RC, superviors's name...etc. I'd like
to create auserformthat can be used to list a given employee and all
the items from their row of data.


So to get me started can someone show me an example of vba code that
will be used in a text box, for example, as a search...ie the user
enters an employee ID number (which is in column A) and then other
text boxes brings in the location, rc and so on in other text boxes
placed on the form. If I can see some example code to pull in the
value from Column A and then Column B that would be a great start for
me. Thanks a ton!- Hide quoted text -


- Show quoted text -


Not sure if an earlier reply to the above message got out there or
not...so I might be repeating myself ....

I was thinking something easier....! I have two fields on my
userform, for now. A combobox1 and a textbox1. The properties for
the Combobox1 has a 'rowsource' of a2:a1600'. This works fine. What
I like Textbox1 do is, when an employee number is selected, say 5375
from cell A34, the textbox1 shows what is in cell B34....which is the
name of the employee....any ideas with this? Thanks for the quick
reply...!!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default userform and VBA code

Then that is just

Dim iRow as long

On Error Resume Next
iRow =
Application.Match(Combobox1.Value,Worksheets("Data ").Columns(1),0)
On Error Goto 0
If iRow 0 Then
TextBox1.Text = Worksheets("Data").Cells(iRow,"B").Value
End If

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
ups.com...
On Jul 11, 11:32 am, "Bob Phillips" wrote:
I would suggest that you get all employee ID and load these into a
combobox.
When a selection is made from there, build an array of records for that
employee and provide back and forward buttons for going through this
array,
and retreive those details and display them.

You can get all unique employees like so

With Worksheets("Data")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
sId = ""
For i = 2 To iLastRow
if .Cells(i,"A").Value < sId Then
sId = .Cells(i,"A").Value
Me.ComboBox1.AddItem .Cells(i,"A").Value
End If
Next I
Me.ComboBox1.ListIndex = -1
End With

You can then load an array like this, and prime it like so

ReDim aryRows(1 To 1)
iRow = 1

With Worksheets("Data")
For i = 2 To iLastRow
If .Cells(i, "A").Value = 1 Then 'Me.Combobox1.Value Then
ReDim Preserve aryRows(1 To iRow)
aryRows(iRow) = i
iRow = iRow + 1
End If
Next i
End With
iRow = 0

and then retrieve like so

Private Sub cmdNext_Click()
With Worksheets("Data")
If iRow = UBound(aryRows) Then
MsgBox "no more"
Else
iRow = iRow + 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub

Private Sub cmdPrevious_Click()
With Worksheets("Data")
If iRow <=1 Then
MsgBox "no more"
Else
iRow = iRow - 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

wrote in message

ups.com...



I'm starting to build a user form in excel and need a push start. I
have an excel file that contains about 15 columns of data with about
1600 rows. The table is a list of all active employees, their
location, department ID, their RC, superviors's name...etc. I'd like
to create auserformthat can be used to list a given employee and all
the items from their row of data.


So to get me started can someone show me an example of vba code that
will be used in a text box, for example, as a search...ie the user
enters an employee ID number (which is in column A) and then other
text boxes brings in the location, rc and so on in other text boxes
placed on the form. If I can see some example code to pull in the
value from Column A and then Column B that would be a great start for
me. Thanks a ton!- Hide quoted text -


- Show quoted text -


Not sure if an earlier reply to the above message got out there or
not...so I might be repeating myself ....

I was thinking something easier....! I have two fields on my
userform, for now. A combobox1 and a textbox1. The properties for
the Combobox1 has a 'rowsource' of a2:a1600'. This works fine. What
I like Textbox1 do is, when an employee number is selected, say 5375
from cell A34, the textbox1 shows what is in cell B34....which is the
name of the employee....any ideas with this? Thanks for the quick
reply...!!!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default userform and VBA code

On Jul 11, 3:25 pm, "Bob Phillips" wrote:
Then that is just

Dim iRow as long

On Error Resume Next
iRow =
Application.Match(Combobox1.Value,Worksheets("Data ").Columns(1),0)
On Error Goto 0
If iRow 0 Then
TextBox1.Text = Worksheets("Data").Cells(iRow,"B").Value
End If

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message

ups.com...



On Jul 11, 11:32 am, "Bob Phillips" wrote:
I would suggest that you get all employee ID and load these into a
combobox.
When a selection is made from there, build an array of records for that
employee and provide back and forward buttons for going through this
array,
and retreive those details and display them.


You can get all unique employees like so


With Worksheets("Data")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
sId = ""
For i = 2 To iLastRow
if .Cells(i,"A").Value < sId Then
sId = .Cells(i,"A").Value
Me.ComboBox1.AddItem .Cells(i,"A").Value
End If
Next I
Me.ComboBox1.ListIndex = -1
End With


You can then load an array like this, and prime it like so


ReDim aryRows(1 To 1)
iRow = 1


With Worksheets("Data")
For i = 2 To iLastRow
If .Cells(i, "A").Value = 1 Then 'Me.Combobox1.Value Then
ReDim Preserve aryRows(1 To iRow)
aryRows(iRow) = i
iRow = iRow + 1
End If
Next i
End With
iRow = 0


and then retrieve like so


Private Sub cmdNext_Click()
With Worksheets("Data")
If iRow = UBound(aryRows) Then
MsgBox "no more"
Else
iRow = iRow + 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub


Private Sub cmdPrevious_Click()
With Worksheets("Data")
If iRow <=1 Then
MsgBox "no more"
Else
iRow = iRow - 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub


--
HTH


Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)


wrote in message


roups.com...


I'm starting to build a user form in excel and need a push start. I
have an excel file that contains about 15 columns of data with about
1600 rows. The table is a list of all active employees, their
location, department ID, their RC, superviors's name...etc. I'd like
to create auserformthat can be used to list a given employee and all
the items from their row of data.


So to get me started can someone show me an example of vba code that
will be used in a text box, for example, as a search...ie the user
enters an employee ID number (which is in column A) and then other
text boxes brings in the location, rc and so on in other text boxes
placed on the form. If I can see some example code to pull in the
value from Column A and then Column B that would be a great start for
me. Thanks a ton!- Hide quoted text -


- Show quoted text -


Not sure if an earlier reply to the above message got out there or
not...so I might be repeating myself ....


I was thinking something easier....! I have two fields on my
userform, for now. A combobox1 and a textbox1. The properties for
the Combobox1 has a 'rowsource' of a2:a1600'. This works fine. What
I like Textbox1 do is, when an employee number is selected, say 5375
from cell A34, the textbox1 shows what is in cell B34....which is the
name of the employee....any ideas with this? Thanks for the quick
reply...!!!- Hide quoted text -


- Show quoted text -


I've tried your suggestion Bill, thanks but I get nothing returned to
textbox1. I've changed the sheet1 to n11, but I still get no data in
the textbox, no errors either?

Private Sub ComboBox1_Change()
Dim iRow As Long
On Error Resume Next
iRow = Application.Match(ComboBox1.Value,
Worksheets("n11").Columns(1), 0)
On Error GoTo 0
If iRow 0 Then
TextBox1.Text = Worksheets("n11").Cells(iRow, "B").Value
End If
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default userform and VBA code

On Jul 11, 4:09 pm, wrote:
On Jul 11, 3:25 pm, "Bob Phillips" wrote:





Then that is just


Dim iRow as long


On Error Resume Next
iRow =
Application.Match(Combobox1.Value,Worksheets("Data ").Columns(1),0)
On Error Goto 0
If iRow 0 Then
TextBox1.Text = Worksheets("Data").Cells(iRow,"B").Value
End If


--
HTH


Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)


wrote in message


oups.com...


On Jul 11, 11:32 am, "Bob Phillips" wrote:
I would suggest that you get all employee ID and load these into a
combobox.
When a selection is made from there, build an array of records for that
employee and provide back and forward buttons for going through this
array,
and retreive those details and display them.


You can get all unique employees like so


With Worksheets("Data")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
sId = ""
For i = 2 To iLastRow
if .Cells(i,"A").Value < sId Then
sId = .Cells(i,"A").Value
Me.ComboBox1.AddItem .Cells(i,"A").Value
End If
Next I
Me.ComboBox1.ListIndex = -1
End With


You can then load an array like this, and prime it like so


ReDim aryRows(1 To 1)
iRow = 1


With Worksheets("Data")
For i = 2 To iLastRow
If .Cells(i, "A").Value = 1 Then 'Me.Combobox1.Value Then
ReDim Preserve aryRows(1 To iRow)
aryRows(iRow) = i
iRow = iRow + 1
End If
Next i
End With
iRow = 0


and then retrieve like so


Private Sub cmdNext_Click()
With Worksheets("Data")
If iRow = UBound(aryRows) Then
MsgBox "no more"
Else
iRow = iRow + 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub


Private Sub cmdPrevious_Click()
With Worksheets("Data")
If iRow <=1 Then
MsgBox "no more"
Else
iRow = iRow - 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub


--
HTH


Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)


wrote in message


roups.com...


I'm starting to build a user form in excel and need a push start. I
have an excel file that contains about 15 columns of data with about
1600 rows. The table is a list of all active employees, their
location, department ID, their RC, superviors's name...etc. I'd like
to create auserformthat can be used to list a given employee and all
the items from their row of data.


So to get me started can someone show me an example of vba code that
will be used in a text box, for example, as a search...ie the user
enters an employee ID number (which is in column A) and then other
text boxes brings in the location, rc and so on in other text boxes
placed on the form. If I can see some example code to pull in the
value from Column A and then Column B that would be a great start for
me. Thanks a ton!- Hide quoted text -


- Show quoted text -


Not sure if an earlier reply to the above message got out there or
not...so I might be repeating myself ....


I was thinking something easier....! I have two fields on my
userform, for now. A combobox1 and a textbox1. The properties for
the Combobox1 has a 'rowsource' of a2:a1600'. This works fine. What
I like Textbox1 do is, when an employee number is selected, say 5375
from cell A34, the textbox1 shows what is in cell B34....which is the
name of the employee....any ideas with this? Thanks for the quick
reply...!!!- Hide quoted text -


- Show quoted text -


I've tried your suggestion Bill, thanks but I get nothing returned to
textbox1. I've changed the sheet1 to n11, but I still get no data in
the textbox, no errors either?

Private Sub ComboBox1_Change()
Dim iRow As Long
On Error Resume Next
iRow = Application.Match(ComboBox1.Value,
Worksheets("n11").Columns(1), 0)
On Error GoTo 0
If iRow 0 Then
TextBox1.Text = Worksheets("n11").Cells(iRow, "B").Value
End If
End Sub- Hide quoted text -

- Show quoted text -


Sorry, I mean to say thanks Bob!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default userform and VBA code

That suggests it isn't finding the value in column A.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
ups.com...
On Jul 11, 3:25 pm, "Bob Phillips" wrote:
Then that is just

Dim iRow as long

On Error Resume Next
iRow =
Application.Match(Combobox1.Value,Worksheets("Data ").Columns(1),0)
On Error Goto 0
If iRow 0 Then
TextBox1.Text = Worksheets("Data").Cells(iRow,"B").Value
End If

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

wrote in message

ups.com...



On Jul 11, 11:32 am, "Bob Phillips" wrote:
I would suggest that you get all employee ID and load these into a
combobox.
When a selection is made from there, build an array of records for
that
employee and provide back and forward buttons for going through this
array,
and retreive those details and display them.


You can get all unique employees like so


With Worksheets("Data")
iLastRow = .Cells(.Rows.Count,"A").End(xlUp).Row
sId = ""
For i = 2 To iLastRow
if .Cells(i,"A").Value < sId Then
sId = .Cells(i,"A").Value
Me.ComboBox1.AddItem .Cells(i,"A").Value
End If
Next I
Me.ComboBox1.ListIndex = -1
End With


You can then load an array like this, and prime it like so


ReDim aryRows(1 To 1)
iRow = 1


With Worksheets("Data")
For i = 2 To iLastRow
If .Cells(i, "A").Value = 1 Then 'Me.Combobox1.Value Then
ReDim Preserve aryRows(1 To iRow)
aryRows(iRow) = i
iRow = iRow + 1
End If
Next i
End With
iRow = 0


and then retrieve like so


Private Sub cmdNext_Click()
With Worksheets("Data")
If iRow = UBound(aryRows) Then
MsgBox "no more"
Else
iRow = iRow + 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub


Private Sub cmdPrevious_Click()
With Worksheets("Data")
If iRow <=1 Then
MsgBox "no more"
Else
iRow = iRow - 1
Me.TextBox1.Text = .Cells(iRow, "A").Value 'emp id
Me.TextBox1.Text = .Cells(iRow, "B").Value 'name
'etc.
End If
End With
End Sub


--
HTH


Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)


wrote in message


roups.com...


I'm starting to build a user form in excel and need a push start. I
have an excel file that contains about 15 columns of data with about
1600 rows. The table is a list of all active employees, their
location, department ID, their RC, superviors's name...etc. I'd
like
to create auserformthat can be used to list a given employee and all
the items from their row of data.


So to get me started can someone show me an example of vba code that
will be used in a text box, for example, as a search...ie the user
enters an employee ID number (which is in column A) and then other
text boxes brings in the location, rc and so on in other text boxes
placed on the form. If I can see some example code to pull in the
value from Column A and then Column B that would be a great start
for
me. Thanks a ton!- Hide quoted text -


- Show quoted text -


Not sure if an earlier reply to the above message got out there or
not...so I might be repeating myself ....


I was thinking something easier....! I have two fields on my
userform, for now. A combobox1 and a textbox1. The properties for
the Combobox1 has a 'rowsource' of a2:a1600'. This works fine. What
I like Textbox1 do is, when an employee number is selected, say 5375
from cell A34, the textbox1 shows what is in cell B34....which is the
name of the employee....any ideas with this? Thanks for the quick
reply...!!!- Hide quoted text -


- Show quoted text -


I've tried your suggestion Bill, thanks but I get nothing returned to
textbox1. I've changed the sheet1 to n11, but I still get no data in
the textbox, no errors either?

Private Sub ComboBox1_Change()
Dim iRow As Long
On Error Resume Next
iRow = Application.Match(ComboBox1.Value,
Worksheets("n11").Columns(1), 0)
On Error GoTo 0
If iRow 0 Then
TextBox1.Text = Worksheets("n11").Cells(iRow, "B").Value
End If
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
code help w/userform Jennifer Excel Programming 2 May 26th 06 03:47 AM
Help with UserForm code. Richard Excel Programming 1 February 24th 06 12:23 AM
Help with UserForm Code sneagle Excel Programming 1 November 18th 05 06:41 PM
Userform Code scrabtree23[_3_] Excel Programming 3 December 5th 04 05:05 AM
VBA code for Userform Martin Los Excel Programming 4 December 5th 03 03:04 PM


All times are GMT +1. The time now is 01:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"