+ Reply to Thread
Results 1 to 5 of 5

Textbox with multiple columns and rows using data from another sheet.

Hybrid View

  1. #1
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Textbox with multiple columns and rows using data from another sheet.

    Dear Friends,

    I have macro to fill textbox in multiple rows and columns. This works only if data is in same sheet. But my data is in another workbook sheet which i need to be used to fill textbox.
    Can some one adjust my code to get data from closed workbook?

    (code which i use is as below. Sample of file is also attached)


    Private Sub UserForm_Initialize()
       
        'Set properties of listbox1
        With Me.ListBox1
            .BoundColumn = 1
            .ColumnCount = 3
            .ColumnHeads = True
            .TextColumn = True
            .RowSource = "Sheet1!A2:C15"
            .ListStyle = fmListStyleOption
            .ListIndex = 0
        End With
    
    End Sub


    Thanks in advance.
    Last edited by ali84pk; 10-17-2011 at 10:32 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Textbox with multiple columns and rows using data from another sheet.

    You are using a ListBox not a TextBox.

    Try this instead
    Option Explicit
    
    Private Sub UserForm_Initialize()
       
        'Set properties of listbox1
        With Me.ListBox1
            .BoundColumn = 1
            .ColumnCount = 3
            .ColumnHeads = True
            .TextColumn = True
            .List = Sheet1.Range("A2:C15").Value
            .ListStyle = fmListStyleOption
            .ListIndex = 0
        End With
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Textbox with multiple columns and rows using data from another sheet.

    hi, ali84pk, as an option to get data for listbox from the closed workbook:

    Private Sub UserForm_Initialize()
    
    Application.ScreenUpdating = 0   - turn off screenupdating
    
        'Set properties of listbox1
        With Me.ListBox1
            .BoundColumn = 1
            .ColumnCount = 3
            .ColumnHeads = True
            .TextColumn = True
            Set wb = Workbooks.Open("C:\Test\Book4.xls") ' - your workbook full path
            x = wb.Sheets("Test").Range("a2:c15") ' - your Sheet name that contains the data required
            .List = x
            .ListStyle = fmListStyleOption
            .ListIndex = 0
        End With
    wb.Close 0
    
    Application.ScreenUpdating = 1 - turn on screenupdating
    
    End Sub

  4. #4
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Textbox with multiple columns and rows using data from another sheet.

    Thanks Roy UK and Watersev.

    Watersev : Your reply fulfills my requirement. thanks again.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Textbox with multiple columns and rows using data from another sheet.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1