Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to use combobox contents to get information for userform

don't use something like vlookup, use vloopup

Dim res as Variant
res =
Application.Vlookup(Range("A1"),Worksheets("Sheet2 ").Range("A1:E200),4,False
)
if not iserror(res) then
msgbox "Returned value is " & res
End if

or to make it easier to do what you want, use Match instead

Dim res as Variant
set rng = Worksheets("Sheet2").Range("A1:E200")
res = Application.Match(Range("A1"), rng,0)
if not iserror(res) then
set rng1 = rng(res).offset(0,4)
msgbox "value returned is: " & res & " at " & rng1.Address(0,0,xlA1,True)
End if

now you can use rng1 to update the cell.


--
Regards,
Tom Ogilvy


"Cheryl" wrote in message
...
I have a user form that contains a combobox that displays all of our

vendors. When I select a vendor, I want to use VBA to retrieve the data for
that vendor such as address.. How do I do this using something similar to
vlookup on the worksheet. Basically, once I display the data.. I want to be
able to edit it.. such as fixing the address and write back to the excel
table it used to retrieve the information..

Thanks in advance for your suggestions or link to a useful resource where

I can find out how to use it...


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to use combobox contents to get information for userform

You could try using the FIND object in the combobox_click event

set rg = Worksheets(1).Range("a1:a500")
With rg 'look in column a for the va
Set c = .Find(combo1.text, lookin:=xlValues)
If Not c Is Nothing Then


End Wit

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default How to use combobox contents to get information for userform

Thank you all... I got this to work..

Private Sub cboBoxCustomer_Change()

Dim SourceRange As Range

Dim Val1 As String

Set SourceRange = Range(cboBoxCustomer.RowSource)

Val1 = cboBoxCustomer.Value

txtVendorID.Text = SourceRange.Offset(cboBoxCustomer.ListIndex, -2).Resize(1, 1).Value
txtType.Text = SourceRange.Offset(cboBoxCustomer.ListIndex, -1).Resize(1, 1).Value
txtName.Text = SourceRange.Offset(cboBoxCustomer.ListIndex, 0).Resize(1, 1).Value
txtDivision.Text = SourceRange.Offset(cboBoxCustomer.ListIndex, 1).Resize(1, 1).Value
txtAddress1.Text = SourceRange.Offset(cboBoxCustomer.ListIndex, 2).Resize(1, 1).Value

etc...

so it now fills in my form with the proper data based on the combo box selection... However... I need to use that information now.. to be able to update the record, once found.... Basically.. I am using the combobox to find the record.. that is tied to a worksheet... Now, I need to be able to update or delete that record based on a command button. I can't seem to make it update.... I think it is because I can't seem to get it to see the row that the found record is currently on to change it.

"dmang " wrote:

You could try using the FIND object in the combobox_click event

set rg = Worksheets(1).Range("a1:a500")
With rg 'look in column a for the va
Set c = .Find(combo1.text, lookin:=xlValues)
If Not c Is Nothing Then


End With


---
Message posted from http://www.ExcelForum.com/


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
Value From ComboBox On UserForm jlclyde Excel Discussion (Misc queries) 3 October 16th 09 01:43 PM
Userform, ComboBox, and Workbooks... Oh my!? fail2excel Excel Discussion (Misc queries) 3 July 31st 09 09:22 PM
ComboBox on a UserForm LLoyd Excel Worksheet Functions 2 February 20th 08 09:01 PM
Yet another userform combobox question teepee Excel Discussion (Misc queries) 4 May 17th 07 10:03 AM
Userform w/ComboBox D.Parker Excel Discussion (Misc queries) 2 May 6th 05 04:28 PM


All times are GMT +1. The time now is 03:00 AM.

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

About Us

"It's about Microsoft Excel"