|
-
Nov 9th, 2007, 03:58 PM
#1
Thread Starter
Junior Member
[RESOLVED] Searching a column of data
I need to be able to search a column for a certain last name. When i find that name, the data associated with it, which is horizontally listed in a spreadsheet will transfer to a textbox in a userform. Anybody have any ideas on how to go about this?
-
Nov 9th, 2007, 04:21 PM
#2
Re: Searching a column of data
use the find method to set a range based on the range of the column you want to search
vb Code:
set rngfound = range("c:c").Find("smith") ' other arguments
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 12th, 2007, 03:12 PM
#3
Frenzied Member
Re: Searching a column of data
Here is the row you are looking for:
Code:
dim aRow as long
dim i as Integer
aRow = rngfound.Row
i = 1 'Init for Column A data if you write a loop
Now you can do a loop or a linear set of instructions copying "Cells(arow, i).Value 'for Col A" etc. into your textboxes on your form.
Does that help?
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Nov 13th, 2007, 08:17 AM
#4
Thread Starter
Junior Member
Re: Searching a column of data
I tried placing "Cells(arow, i).Value 'for Col A" in the Textbox properties. I pasted it in the Name and Data text locations. Neither one worked properly. Where should I paste it then?
-
Nov 13th, 2007, 08:44 AM
#5
Frenzied Member
Re: Searching a column of data
I was under the impression that you are trying to write VBA code for a Macro. That's what this forum is all about ... "Visual Basic".
Cells(arow, i).Value is part of a VBA instruction that fetches the value out of a cell on the sheet. Once you have that value, you have to have code to paste it into the proper text box. You will need to know how to reference the form and textbox in code. That isn't hard, but it depends on the Form Name property and the TextBox Name property.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Nov 13th, 2007, 03:30 PM
#6
Re: Searching a column of data
vb Code:
textbox1.text = sheets("sheet1").cells(arow,1).value 'from col A
textbox2.text = sheets("sheet1").cells(arow,2).value 'form col B
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 14th, 2007, 01:25 PM
#7
Thread Starter
Junior Member
Re: Searching a column of data
Thanks guys!!! Hey could I put the same text in two seperate userforms? I tried this code but it just takes me too Userform2.
vb Code:
Private Sub CommandButton1_Click()
Dim aRow As Long
Dim i As Integer
Dim rngfound As Variant
Set rngfound = Range("B:B").Find(LName.Text) ' other arguments
aRow = rngfound.Row
FName.Text = Cells(aRow, 1).Value 'for Col A
LName.Text = Cells(aRow, 2).Value 'for Col B
UserForm2.Show
firstname.Text = Cells(aRow, 1).Value 'for Col A
LastName.Text = Cells(aRow, 2).Value 'for Col B
End Sub
-
Nov 14th, 2007, 03:33 PM
#8
Re: Searching a column of data
vb Code:
userform2.firstname.Text = Cells(aRow, 1).Value 'for Col A
userform2.LastName.Text = Cells(aRow, 2).Value 'for Col B
UserForm2.Show
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|