+ Reply to Thread
Results 1 to 3 of 3

ListView & Horizontal Range

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2012
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    8

    ListView & Horizontal Range

    Question asked also on : http://www.ozgrid.com/forum/showthre...505#post699505

    Hello the forum

    Lines that fill a listview are usually arranged vertically in the data sheet, in my case they are arranged horizontally

    For now I can fill the listview, send listview values to the sheet, but my code is long, I need to reduce it with loops

    It would be very nice if someone could give me help

    Private Sub CommandButton1_Click()
    Dim Sh As Worksheet, Li As Long, c As Integer, i As Integer, j As Integer
    Set Sh = Sheets("Test")
    Li = Sh.[B:B].Find(ListBox1, LookIn:=xlValues).Row
        Sh.Cells(Li, 15) = ListView1.ListItems(1).Text
        Sh.Cells(Li, 16) = ListView1.ListItems(1).ListSubItems(1).Text
        Sh.Cells(Li, 17) = ListView1.ListItems(1).ListSubItems(2).Text
        Sh.Cells(Li, 18) = ListView1.ListItems(1).ListSubItems(3).Text
        Sh.Cells(Li, 19) = ListView1.ListItems(1).ListSubItems(4).Text
        Sh.Cells(Li, 20) = ListView1.ListItems(1).ListSubItems(5).Text
        Sh.Cells(Li, 21) = ListView1.ListItems(1).ListSubItems(6).Text
    
        Sh.Cells(Li, 22) = ListView1.ListItems(2).Text
        Sh.Cells(Li, 23) = ListView1.ListItems(2).ListSubItems(1).Text
        Sh.Cells(Li, 24) = ListView1.ListItems(2).ListSubItems(2).Text
        Sh.Cells(Li, 25) = ListView1.ListItems(2).ListSubItems(3).Text
        Sh.Cells(Li, 26) = ListView1.ListItems(2).ListSubItems(4).Text
        Sh.Cells(Li, 27) = ListView1.ListItems(2).ListSubItems(5).Text
        Sh.Cells(Li, 28) = ListView1.ListItems(2).ListSubItems(6).Text
    
        Sh.Cells(Li, 29) = ListView1.ListItems(3).Text
        Sh.Cells(Li, 30) = ListView1.ListItems(3).ListSubItems(1).Text
        Sh.Cells(Li, 31) = ListView1.ListItems(3).ListSubItems(2).Text
        Sh.Cells(Li, 32) = ListView1.ListItems(3).ListSubItems(3).Text
        Sh.Cells(Li, 33) = ListView1.ListItems(3).ListSubItems(4).Text
        Sh.Cells(Li, 34) = ListView1.ListItems(3).ListSubItems(5).Text
        Sh.Cells(Li, 35) = ListView1.ListItems(3).ListSubItems(6).Text
    
        Sh.Cells(Li, 36) = ListView1.ListItems(4).Text
        Sh.Cells(Li, 37) = ListView1.ListItems(4).ListSubItems(1).Text
        Sh.Cells(Li, 38) = ListView1.ListItems(4).ListSubItems(2).Text
        Sh.Cells(Li, 39) = ListView1.ListItems(4).ListSubItems(3).Text
        Sh.Cells(Li, 40) = ListView1.ListItems(4).ListSubItems(4).Text
        Sh.Cells(Li, 41) = ListView1.ListItems(4).ListSubItems(5).Text
        Sh.Cells(Li, 42) = ListView1.ListItems(4).ListSubItems(6).Text
    Unload Me
    End Sub
    Cordially, Kim.
    Attached Files Attached Files
    Last edited by Kimaos; 01-26-2014 at 06:04 PM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: ListView & Horizontal Range

    Also: http://www.ozgrid.com/forum/showthread.php?t=185646 (Answered)

  3. #3
    Registered User
    Join Date
    04-24-2012
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: ListView & Horizontal Range

    Hello Cytop,

    Yes the answer was :

    Private Sub CommandButton1_Click()
    Dim Sh As Worksheet, Li As Long, c As Long, i As Long, j As Long
    Set Sh = Sheets("Test")
    Li = Sh.[B:B].Find(ListBox1, LookIn:=xlValues).Row
    For c = 15 To 42 Step 7
        i = i + 1
        Sh.Cells(Li, c) = ListView1.ListItems(i).Text
        For j = 1 To 6
            Sh.Cells(Li, c + j) = ListView1.ListItems(i).ListSubItems(j).Text
        Next j
    Next c
    Unload Me
    End Sub
    Thanks ! Kim.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. SUMIF with Horizontal sum range
    By mennojim in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-18-2013, 04:26 PM
  2. Horizontal alignment with a range in a row
    By jason_kelly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2012, 01:40 AM
  3. Listview checked row delete line in Listview and in worksheet data
    By madforit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2012, 01:00 PM
  4. Replies: 2
    Last Post: 04-16-2011, 07:48 AM
  5. sumproduct w/horizontal range not working
    By dcd123 in forum Excel Formulas & Functions
    Replies: 66
    Last Post: 09-06-2005, 07:05 PM

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