PDA

View Full Version : [SOLVED:] Multiple Ifs/Loops



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

SamT
06-08-2017, 03:46 AM
You marked the thread "Solved." Do you still have the problem?

I see lindex2.
There ain't no such thing. Perhaps you mean ListIndex(2, 3)

Using Option Explicit, and Compiling the code would have pointed this out.

Olwa
06-08-2017, 04:58 AM
Hi sam,
lindex2 is a variable i'm using to start "counting" from the row i found before (therefor i coded the line lindex2 = lindex + 1). I did however solve the problem in a different way after some testing so i marked it as solved. Thanks however.