Insert Listbox Content on Double Click

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

I'm using the following code to insert the list box content to the cells "I25:I33" and cells "K25:K33".
Code:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  Dim r As Long
  With Worksheets("MySheet")
    If Range("I25") = "" Then
      r = 25
    Else
      r = .Range("I24").End(xlDown).Row + 1
    End If
    .Range("I" & r) = Me.ListBox1.Column(1)
  End With
End Sub
But the code inserts the listbox contents from I25 and onwards until the last row of the excel sheet.

How can I modify the code, so that when the user double clicks the list box; the double clicked row contents get copied to rows starting from I25:I33 and then to K25:K33.

Any help on this would be kindly appreciated.

Thanks in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Somewhat unclear... If, for example, you'd like to copy the double-clicked row to the first available row in Column I, starting at I25, try...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] ListBox1_DblClick([color=darkblue]ByVal[/color] Cancel [color=darkblue]As[/color] MSForms.ReturnBoolean)
    [color=darkblue]Dim[/color] LastRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] r [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]With[/color] Worksheets("MySheet")
        LastRow = .Cells(.Rows.Count, "I").End(xlUp).Row
        [color=darkblue]If[/color] LastRow >= 25 [color=darkblue]Then[/color]
            r = LastRow + 1
        [color=darkblue]Else[/color]
            r = 25
        [color=darkblue]End[/color] [color=darkblue]If[/color]
        .Cells(r, "I").Value = Me.ListBox1.Column(1)
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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