Olwa
06-08-2017, 01:09 AM
Hi there,
I cant seem to figure out the right way to do this:
I want to find the first row, in which the cell in column 3 contains the value marked in the listbox. I then want to check if there is another row with the same value in column 3. If so, i want to (for this example) give out a message box, if not a different one. After that i want to change the cells of column 1 and 2 to 000/00000 in the first row found ("lindex"). Im getting an error within the row that is coded with an Or. Thanks in advance!
Private Sub Label27_Click()
If ListBox1.ListIndex >= 0 Then
lindex = 2
Do While Sheets(1).Cells(lindex, 3).Value <> ListBox1.Text
lindex = lindex + 1
Loop
If ListBox1.Text = Sheets(1).Cells(lindex, 3).Value Then
lindex2 = lindex + 1
Do While Sheets(1).Cells(lindex2, 3).Value <> ListBox1.Text Or Sheets(1).Cells(lindex2, 3).Value <> ""
lindex2 = lindex2 + 1
Loop
If Sheets(1).Cells(lindex2, 3).Value = ListBox1.Text Then
MsgBox "Do Exist!", vbOKOnly, "Yes"
Else
MsgBox "Dont Exist!", vbOKOnly, "No"
End If
End If
Sheets(1).Cells(lindex, 1).Value = "000"
Sheets(1).Cells(lindex, 2).Value = "00000"
End If
End Sub
I cant seem to figure out the right way to do this:
I want to find the first row, in which the cell in column 3 contains the value marked in the listbox. I then want to check if there is another row with the same value in column 3. If so, i want to (for this example) give out a message box, if not a different one. After that i want to change the cells of column 1 and 2 to 000/00000 in the first row found ("lindex"). Im getting an error within the row that is coded with an Or. Thanks in advance!
Private Sub Label27_Click()
If ListBox1.ListIndex >= 0 Then
lindex = 2
Do While Sheets(1).Cells(lindex, 3).Value <> ListBox1.Text
lindex = lindex + 1
Loop
If ListBox1.Text = Sheets(1).Cells(lindex, 3).Value Then
lindex2 = lindex + 1
Do While Sheets(1).Cells(lindex2, 3).Value <> ListBox1.Text Or Sheets(1).Cells(lindex2, 3).Value <> ""
lindex2 = lindex2 + 1
Loop
If Sheets(1).Cells(lindex2, 3).Value = ListBox1.Text Then
MsgBox "Do Exist!", vbOKOnly, "Yes"
Else
MsgBox "Dont Exist!", vbOKOnly, "No"
End If
End If
Sheets(1).Cells(lindex, 1).Value = "000"
Sheets(1).Cells(lindex, 2).Value = "00000"
End If
End Sub