Results 1 to 5 of 5

Thread: load workbook data to UserForm

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Unhappy load workbook data to UserForm

    I would like to load data to UserForm. I wrote the code, but I do not know where is the mistake.

    Please help

    VB Code:
    1. Sub Show_HK()
    2.  
    3. UserForm2.KeepScrollBarsVisible = fmScrollBarsNone
    4. UserForm2.ScrollBars = fmScrollBarsVertical
    5. UserForm2.Spreadsheet1.Toolbar.Appearance = cc3D
    6.  
    7. Dim i As Long, j As Long, k As Long
    8.  
    9. k = Worksheets("$").range("D3").Value
    10.     For i = 1 To k
    11.         For j = 1 To 12
    12.             UserForm2.Spreadsheet1.Cells(i, j).Value = Workbooks("C:\Documents and Settings\bolcskei\Dokumenty\FA\TV\HKA 2004 1.0.xls").Worksheet("HK2").Cells(i, j).Value
    13.         Next j
    14.     Next i
    15. UserForm2.Show (vbModeless)
    16. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: load workbook data to UserForm

    What is the error? Just a comment, but whygo to all the trouble of creating an
    Excel userform with the entire spreadsheet contents? Why not just use Excel as is for this?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: load workbook data to UserForm

    Quote Originally Posted by RobDog888
    What is the error? Just a comment, but whygo to all the trouble of creating an
    Excel userform with the entire spreadsheet contents? Why not just use Excel as is for this?
    When I run the macro error 9 I receive. When I am working with some data on the sheet somethimes I would like to see another datas which are not present on the activated sheet, but I do not want to open and close some other excel files. For example when I am working with Balance Sheet of the company I would like to check datas from the Main book. My aim to load data the using UserForm could be more confortable to use.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: load workbook data to UserForm

    I would have to think that the subscript out of range error is from this line
    of code because the dollar sign is a reserved character in Excel. It thinks
    there should be a value after it. Try changing the sheet name to something
    else.

    VB Code:
    1. k = Worksheets("$").range("D3").Value
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: load workbook data to UserForm

    Quote Originally Posted by RobDog888
    I would have to think that the subscript out of range error is from this line
    of code because the dollar sign is a reserved character in Excel. It thinks
    there should be a value after it. Try changing the sheet name to something
    else.

    VB Code:
    1. k = Worksheets("$").range("D3").Value
    No. I have problem with this:
    VB Code:
    1. UserForm2.Spreadsheet1.Cells(i, j).Value = Workbooks("C:\Documents and Settings\bolcskei\Dokumenty\FA\TV\HKA 2004 1.0.xls").Worksheet("HK2").Cells(i, j).Value

Posting Permissions

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



Click Here to Expand Forum to Full Width