loop not getting me there

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I used this code for my listbox click event. When it sends data to the textboxes, it places the data in the first column in Reg2 instead of Reg1. How do i get my data in place????

Code:
Private Sub lstWin_Click()
Dim n As Integer, ac As Integer

With lstWin
       For n = 0 To .ListCount - 1
              If .Selected(n) Then 
                       For ac = 0 To .ColumnCount - 1
                                Me.Controls("Reg" & ac + 1).Value = .List(n, ac - 1)
                      Next ac
            End If
      Next n
End With
End Sub

Thanks in advance
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi!

This will get you there:

Code:
Private Sub lstWin_Click()
Dim n As Integer, ac As Integer
With lstWin
       For n = 0 To .ListCount - 1
              If .Selected(n) Then
                       For ac = 1 To .ColumnCount
                                Me.Controls("Reg" & ac).Value = .List(n, ac - 1)
                      Next ac
            End If
      Next n
End With
End Sub

But this will get you there faster :biggrin::

Code:
Private Sub lstWin_Click()
Dim ac As Integer
With lstWin
    For ac = 1 To .ColumnCount
        .TextColumn = ac
        Me.Controls("Reg" & ac).Value = .Text
    Next ac
End With
End Sub

Regards,

CJ
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top