Listbox vs Textbox

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I am using the code below to pass information on a userform to a WS. It is a code that I have used for years and has been very reliable. I am writing up a new userform WB for a new project and for some reason I cannot get this code to work correctly. Well, more exactly it works fine for the "Device List" WS - everything there is good, but when it moves to the "Repair Log" WS section it does not place the values in the correct row. Instead of placing the data on the row that corresponds with DeviceId.Value, it always puts it on the next blank row at the end, regardless of where that DeviceID.Value is.

The only difference that I can see in my workbooks is that I usually use a textbox for these entries on my userform, but in this case I need to use a listbox. Could this be the reason why its not working correctly? I appreciate your input - thanks,

VBA Code:
Private Sub CommentButton_Click()

    Dim i As Long
    Dim Lastrow As Long
    Dim Found As Range
       
   
    Worksheets("Device List").Activate
    
    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    
        For i = 1 To Lastrow
            If Cells(i, 8).Value = "FAIL" And Cells(i, 7).Value = "" Then
            Cells(i, 7).Value = RepairComments.Value
            
    
    'insert code to pass the comments to the relevant repair log row
    
    Sheets("Repair Log").Activate
    
        Set Found = Sheets("Repair Log").Range("A:A").Find(What:=Me.DeviceId.Value, _
                                                       LookIn:=xlValues, _
                                                       LookAt:=xlWhole, _
                                                       SearchOrder:=xlByRows, _
                                                       SearchDirection:=xlNext, _
                                                       MatchCase:=False)
        If Found Is Nothing Then
            MsgBox "No match for " & Me.DeviceId.Value, , "No Match Found"
        Else
            Found.Offset(0, 2).Value = Me.RepairComments.Value
            
     End If
    
   
    Exit For
    End If
    Next
    
'some more code here..... :)
    
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Untested, but try removing this line:
VBA Code:
Sheets("Repair Log").Activate
 
Upvote 0
Sorry, you have "Exit For" before the "End If", so I don't think removing the line would matter.
I usually use a textbox for these entries on my userform, but in this case I need to use a listbox.
Which one is the listbox? DeviceId?
For debugging, try checking the value first with a message box. See if the value is correct.

Rich (BB code):
        Sheets("Repair Log").Activate
        MsgBox Me.DeviceId.Value
 
Upvote 0
Sorry, you have "Exit For" before the "End If", so I don't think removing the line would matter.

Which one is the listbox? DeviceId?
For debugging, try checking the value first with a message box. See if the value is correct.

Rich (BB code):
        Sheets("Repair Log").Activate
        MsgBox Me.DeviceId.Value
yeah, the listbox is holding the value correctly, its just not putting it in the correct spot on the WS. For some reason the "Set Found" portion is not finding the correct row, not matching the deviceid value to the matching one on the sheet - I cannot figure why because the syntax of the search appears to be correct to me. I thought maybe a listbox needed different wording or something in code.....
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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