Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Populate a userform from a worksheet

I hope someone is able to help me with this problem. Its driving me crazy!
Ill try to explain it in the simplest way possible.
I have a workbook with 2 worksheets. Sheet2 contains a table as follows:

A B C
1 Branch Name Address Phone
2 USA LA 123456
3 France Paris 123658
4 England London 125698
etc

In sheet1, the Branch Names (USA, France, England, etc) are listed say in
column A. The user can select a cell containing a Branch Name then click on a
control button View Details. When this button is clicked, I want a userform
to appear displaying the details (Address and Phone) of the selected branch.
Below is the code Im using. The problem is that every time the userform
appears, it shows the details of the branch that was 'last' selected, not the
branch 'currently' selected. For example, if I last selected USA, and now I
want to see France, I get the details of USA. Then if I select England, I get
the details of France, etc. Can anyone put me in the right direction please?
Here is my code

Private Sub CommandButton3_Click()

' In sheet1, check which branch is selected
Dim x As String
x = ActiveCell.Value

' In sheet2, search for the row number of the row containing the selected
branch
Sheets(Sheet2).Range("Branch").Select
Selection.Find(what:=x).Select

Dim RowNum As Long
RowNum = ActiveCell.Row

' Import the worksheet data onto a userform called View_Form
View_Form.Show
Set View_Form = Nothing

View_Form.Controls("BranchName").ControlSource = _
Sheets("Sheet2").Cells(RowNum, 1).Address

View_Form.Controls("Address").ControlSource = _
Sheets("Sheet2").Cells(RowNum, 2).Address

View_Form.Controls("Phone").ControlSource = _
Sheets("Sheet2").Cells(RowNum, 3).Address

End Sub

I tried populating the form using this code instead, but Im still having
the same problem:

View_Form.Controls("Phone").value = _
Sheets("Sheet2").Cells(RowNum, 3).value


Im using Excel 2003. Many thanks
Tendresse
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Populate a userform from a worksheet

Check out this example, it uses Vlookup in VBA to to populate the tex
tboxes from a selection made in a combobox

http://sites.google.com/site/davesex...attredirects=0
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
Populate multi-column list in worksheet not in a UserForm Afzal Excel Programming 2 June 12th 08 11:50 PM
Populate sheet from userform cityfc Excel Programming 6 April 15th 06 11:18 PM
Populate Userform from another workbook Ryan Excel Programming 0 May 12th 04 09:31 PM
Userform using 3 ranges to populate. Todd Huttenstine[_2_] Excel Programming 1 December 13th 03 12:33 AM
Populate Userform text boxes in VBA with VLookup data from #2 worksheet Laz[_2_] Excel Programming 4 October 8th 03 02:15 AM


All times are GMT +1. The time now is 10:16 PM.

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"