PDA

View Full Version : Solved: For Next help



Emoncada
05-17-2013, 10:58 AM
I have the following code

Dim Search As String
Dim ws As Worksheet
Dim aCell As Range
Dim i As Long
Set ws = Worksheets("Data")
For i = 1 To 25

If Me.Controls("Combobox" & i).Value = "Shipped" Then

Next i

Else

With ws

Search = Me.Controls("Textbox" & i).Value

Set aCell = .Columns(74).Find(What:=Search, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not aCell Is Nothing Then
.Rows(aCell.Row).ClearContents
End If

End With
End If

Next i

I have the following layout.
I have 25 textboxes next to a 25 comboBoxes

I want if the Combobox = "Shipped" then Go to Next Combobox
Else
I want it to search textbox value and delete row on sheet, then
loop back to next line.

I keep getting a Compile Error
Next without For

Paul_Hossler
05-17-2013, 11:08 AM
I don't think you can use your first Next i like that


For i = 1 To 25
If Me.Controls("Combobox" & i).Value <> "Shipped" Then
With ws
Search = Me.Controls("Textbox" & i).Value

Set aCell = .Columns(74).Find(What:=Search, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not aCell Is Nothing Then
.Rows(aCell.Row).ClearContents
End If
End With
End If
Next i


Paul

Emoncada
05-17-2013, 11:30 AM
Thanks for the reply Paul, I am not getting an error now, but it's not working. Any idea why??

Emoncada
05-17-2013, 11:41 AM
Nevermind I got it working by changing (74) to the Column name ("CB")

Thanks