Where's the Problem - Waldo?

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
This Code worked and all of a sudden it doesnt. I dont recall making any changes that would have caused it not to work. I dont get an error message. Its just no longer listed the selections from ListBox1 in Column L

Code:
Private Sub CommandButton2_Click()

    Range("L1:L200").Select
    Selection.ClearContents
'
Dim Msg As String
    Dim i As Integer
    Dim c As Integer
    Dim NextRow As Long
    Dim LastRow As Long

    Worksheets("Tables").Select
    
    Range("L1").Select
'   Determine the next empty row
    NextRow = Application.WorksheetFunction. _
       CountA(Range("L:L")) + 1
'   Transfer the selected items from ListBox
    For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
c = c + 1
Cells(LastRow + c, 12) = ListBox1.List(i, 0)
End If
Next i
'
'    Sheets("Tables").Calculate

End Sub
 
Norie and Heyman.

Maybe i'm missing something but i cant understand the reason of getting NextRow...

The range is being cleared in the first code-line and NextRow is not used for anything...

I'm lost :confused:

M.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I used this code in another Excel workbook and copied it into this one. Tweaked it a little bit for Column differences. It works terrific in the other book and was working here so I did not bother with LastRow.

You are right, I am not adding onto the bottom of a previous list in column L. But if I take that out, it doesnt fix the problem.

Nori's code seems to be working for Nori runs it, but it doesnt work for me.

I must have something going on in other code that I have in this workbook thats screwing up this. I just cant figure it out and its driving me nuts.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

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