Else without If error after a bunch of ElseIf statements - excel

I'm getting an Else without If error after all my ElseIf statements. I'm trying to end my initial If AColValue = "LV Fuses" with an Else statement but it's giving me this error at the Else.
Do While j <> 1
If AColValue = "LV Fuses" Then 'Fuse info starts with a row labelled "LV Fuses" in Col A
j = 1
Exit Do
ElseIf AColValue = "HV/MV with Trip-Unit" Then '
j = 1
Exit Do
ElseIf AColValue = "HV/MV without Trip-Unit" Then '
j = 1
Exit Do
ElseIf AColValue = "Relays" Then '
j = 1
Exit Do
ElseIf AColValue = "MCP" Then '
j = 1
Exit Do
ElseIf AColValue = "MOL" Then '
j = 1
Exit Do
ElseIf AColValue = "HV Fuses" Then '
j = 1
Exit Do
ElseIf AColValue = "Switches" Then '
j = 1
Exit Do
ElseIf AColValue = "" Then '
NumOfBkrs = NumOfBkrs + 1
RowNumberPlus1 = RowNumber + 1
AColValue = Range("A" & RowNumberPlus1)
If AColValue = "" Then
RowNumberPlus1 = RowNumberPlus1 + 1
AColValue = Range("A" & RowNumberPlus1)
If AColValue = "" Then
j = 1
End If
End If
End If
Else
RowNumber = RowNumber + 1
End If
AColValue = Range("A" & RowNumber)
Loop

Your second to last End If closes the main If.
Then, the following Else has no If.

Related

Add ComboBox in an Interactive UserForm in VBA

I am using this tutorial (https://www.excel-easy.com/vba/examples/interactive-userform.html) for how to create an Interactive Userform that overwrites values based on a simple condition that if ID exists, then update or edit the rows.
However, this works very well for TextBox but I am struggling to add other controls from the Toolbox. Currently, I am trying to add ComboBox in the loops such that it can add values from the ComboBox.
Private Sub ComboBox1_Change()
End Sub
Private Sub CommandButton1_Click()
EditAdd
End Sub
Private Sub CommandButton2_Click()
ClearForm
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub TextBox1_Change()
GetData
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
TextBox1.SetFocus
ComboBox1.AddItem "One"
ComboBox1.AddItem "Two"
ComboBox1.AddItem "Three"
ComboBox1.AddItem "Four"
ComboBox1.AddItem "Five"
End Sub
Here is the module. I've tried to modify it by adding UserForm.Controls("ComboBox" & j).Value = Cells(i + 1, j).Value in the for loops, but I only get errors.
Dim id As Integer, i As Integer, j As Integer, flag As Boolean
Sub GetData()
If IsNumeric(UserForm.TextBox1.Value) Then
flag = False
i = 0
id = UserForm.TextBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 6
UserForm.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
UserForm.Controls("ComboBox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 2 To 6
UserForm.Controls("TextBox" & j).Value = ""
UserForm.Controls("ComboBox" & j).Value = ""
Next j
End If
Else
ClearForm
End If
End Sub
Sub ClearForm()
For j = 1 To 6
UserForm.Controls("TextBox" & j).Value = ""
UserForm.Controls("ComboBox" & j).Value = ""
Next j
End Sub
Sub EditAdd()
Dim emptyRow As Long
If UserForm.TextBox1.Value <> "" Then
flag = False
i = 0
id = UserForm.TextBox1.Value
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 6
Cells(i + 1, j).Value = UserForm.Controls("TextBox" & j).Value
Cells(i + 1, j).Value = UserForm.Controls("ComboBox" & j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 1 To 6
Cells(emptyRow, j).Value = UserForm.Controls("TextBox" & j).Value
Cells(emptyRow, j).Value = UserForm.Controls("ComboBox" & j).Value
Next j
End If
End If
End Sub
How can I add ComboBox into my module such that the Userform overwrites existing values if ID exists?
I can't provide a full answer because I don't understand enough about what you are trying to achieve - hence the various comments and queries in the code. Perhaps it gives you enough to work out what you have to do.
Dim id As Integer, i As Integer, j As Integer, flag As Boolean
Sub GetData()
If IsNumeric(UserForm.TextBox1.Value) Then 'separate check required for combobox?
flag = False
i = 0
id = UserForm.TextBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If UserForm.ComboBox1.Value = Cells(i + 1, j).Value Then 'not sure if this check is right and the j needs to be replaced with something
'do something
'should this be a separate flag?
End If
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 6
UserForm.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then 'might need changing if separate flags required
UserForm.ComboBox1.Value = ""
For j = 2 To 6
UserForm.Controls("TextBox" & j).Value = ""
Next j
End If
Else
ClearForm
End If
End Sub

Error-91 VB script error

I keep getting error91 come up when I run my code which says that the object variable is not set.
It highlights the line:
'If OptionButton3.Value Then' when I try the debugger. I don't understand where its going wrong and I don't know what an object variable is? Has anyone else had this issue?
Any help would be much appreciated. Thank you
Sub NewEntry()
Dim cboOpName As Object
Dim TextBox1 As Object
Dim Operator As String
Dim UserForm1 As Object
Dim OptionButton1 As Object
Dim OptionButton3 As Object
Dim OptionButton11 As Object
Sheets("Sheet1").Activate
txtTitle1 = "Input Operator"
firstline1 = "Operator" & Chr(10) & Chr(10)
firstline = (firstline1)
Oper = InputBox(firstline, txtTitle1)
If Oper = "" Then
Exit Sub
Else
End If
If Oper = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Project ID Number"
firstline3 = "Project ID No" & Chr(10) & Chr(10)
firstline = (firstline3)
PROno = InputBox(firstline, txtTitle1)
If PROno = "" Then
Exit Sub
Else
End If
If PROno = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Date of Manufacture"
firstline3 = "Date of Manufacture" & Chr(10) & Chr(10)
firstline = (firstline3)
val1 = "DD/MM/YY"
DateM = InputBox(firstline, txtTitle1, val1)
If DateM = "" Then
Exit Sub
Else
End If
If DateM = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Serial Number"
firstline3 = "Serial Number" & Chr(10) & Chr(10)
firstline = (firstline3)
SerNo = InputBox(firstline, txtTitle1)
If SerNo = "" Then
Exit Sub
Else
End If
If SerNo = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Actuator ID"
firstline3 = "Actuator ID" & Chr(10) & Chr(10)
firstline = (firstline3)
ActID = InputBox(firstline, txtTitle1)
If ActID = "" Then
Exit Sub
Else
End If
If ActID = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Opening Angle"
firstline3 = "Opening Angle" & Chr(10) & Chr(10)
firstline = (firstline3)
Angle = InputBox(firstline, txtTitle1)
If Angle = "" Then
Exit Sub
Else
End If
If Angle = 0 Then
Exit Sub
Else
End If
txtTitle1 = "Input Date of Test"
firstline3 = "Date of Test" & Chr(10) & Chr(10)
firstline = (firstline3)
DateT = InputBox(firstline, txtTitle1, val1)
val1 = "DD/MM/YY"
If DateT = "" Then
Exit Sub
Else
End If
If DateT = 0 Then
Exit Sub
Else
End If
UserForm2.Show
UserForm4.Show
Sheets("Sheet1").Activate
RowNow = 6
RowNum = 1
Do While RowNow = ""
If RowNow <> "" Then
RowNow = RowNow + 1
RowNum = RowNum + 1
Else
Cells(RowNow, 1).Value = RowNum
Cells(RowNow, 4).Value = PROno
Cells(RowNow, 9).Value = DateM
Cells(RowNow, 7).Value = SerNo
Cells(RowNow, 8).Value = ActID
Cells(RowNo, 2).Value = DateT
Cells(RowNow, 3).Value = Oper
Cells(RowNow, 10).Value = Angle
End If
Loop
Do While Cells(RowNow, 11) = ""
If OptionButton3.Value Then
Cells(RowNow, 11).Value = "Yes"
End If
Cells(RowNow, 11).Value = "No"
RowNow = RowNow + 1
Loop
Do While Cells(RowNow, 6) = ""
If OptionButton11.Value Then
Cells(RowNow, 6).Value = "Yes"
End If
Cells(RowNow, 6).Value = "No"
RowNow = RowNow + 1
Loop
Do While Cells(RowNow, 5) = ""
If OptionButton1.Value Then
Cells(RowNow, 5).Value = "Yes"
End If
Cells(RowNow, 5).Value = "No"
RowNow = RowNow + 1
Loop
End Sub
​

I am getting a error because my value is Text and it is looking for a Numeric Value how do I fix this?

I am not a VBA programmer and I need help.
In my spreadsheet my Location (ComboBox1) is text and I can not change it to be numeric. How do I fix it so it will use the Text. I guess I need to use the IsText function but I can not figure out how.
My code is pasted below. The first line after GetData() is where it stops.
Dim Loc As Integer, i As Integer, j As Integer, flag As Boolean
Sub GetData()
If IsNumeric(UserForm1.ComboBox1.Value) Then
flag = False
i = 0
id = UserForm1.ComboBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 2 To 3
UserForm1.Controls("TextBox" & j).Value = ""
Next j
End If
Else
ClearForm
End If
End Sub
Sub ClearForm()
For j = 1 To 3
UserForm1.Controls("TextBox" & j).Value = ""
Next j
End Sub
Sub EditAdd()
Dim emptyRow As Long
If UserForm1.ComboBox1.Value <> "" Then
flag = False
i = 0
id = UserForm1.ComboBox1.Value
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 3
Cells(i + 1, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 1 To 3
Cells(emptyRow, j).Value = UserForm1.Controls("TextBox" & j).Value
Next j
End If
End If
End Sub

Look for keywords and copy to another sheet

I currently have a working code that does exactly what I want it to do, loops through a particular part of an excel document looking for certain keywords, then pasting those keywords into a separate sheet in the excel spreadsheet. It is just very long and doesn't allow for any more than 10 repetitions. I was wondering if anyone had advice on making this code loop until the user selects vbNo when asked if they have any more keywords?
Option Compare Text
Sub Macro2()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+h
'
Application.ScreenUpdating = False
Dim lastLine As Long
Dim findWhat As String
Dim toCopy As Boolean
Dim cell As Range
Dim i As Long
Dim j As Long
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
s = 2
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
If MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion) = vbNo Then Exit Sub
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Rows(i).Copy Destination:=Sheets(s).Rows(j)
j = j + 1
End If
toCopy = False
Next
s = s + 1
What you want to do is make a loop that will continue until the user chooses to stop by hitting cancel in your input box. To start the loop, set the loop check variable, "continue" to be equal to the result of clicking 'yes' on the box that asks if the user wants to continue.
Then, after executing the code, ask the user if they wish to add another word. If not, the loop will end. If so, the loop will continue and do another word.
Here's a start....
Dim Continue As Long
Dim findWhat As String
Dim LastLine As Long
Dim toCopy As Boolean
Dim cell As Range
Dim i As Long
Dim j As Long
Dim newsheet As Worksheet
s = 2
Continue = vbYes 'initialize loop variable
Do While Continue = vbYes 'keep getting more use input until they state they do not want to continue
findWhat = CStr(InputBox("What word would you like to search for today?"))
lastLine = ActiveSheet.UsedRange.Rows.Count
If findWhat = "" Then Exit Sub
j = 1
For i = 1 To lastLine
For Each cell In Range("BU1").Offset(i - 1, 0)
If InStr(cell.Text, findWhat) <> 0 Then
toCopy = True
End If
Next
If toCopy = True Then
Set newsheet = activeworkbook.sheets.add
newsheet.name = findWhat
Rows(i).Copy Destination:=newsheet.Rows(j)
j = j + 1
End If
Set newsheet = Nothing
toCopy = False
Next i
s = s + 1
'find out if user wishes to continue.
Continue = MsgBox(((j - 1) & " results were copied, do you have more keywords to enter?"), vbYesNo + vbQuestion)
Loop

Everything seems to work except placing string in cells

This code doesn't print -1 and 0 when it's supposed,
but everything else works fine.
It iterates through both lists: (Sheet1 and edi_partnere)
and exits loops when it's supposed.
Q: What am I missing: why isn't cells().value catching?
Do
If orgnr1 = "" Then Exit Sub
Do
orgnr2 = Sheets("edi_partnere").Cells(j, 1).Value
If orgnr2 = orgnr1 Then
Sheets("Sheet1").Cells(j, 9).Value = "-1" 'not happening
Exit Do
ElseIf orgnr2 = "" Then
Sheets("Sheet1").Cells(j, 9).Value = "0" 'not happening
Exit Do
Else: j = j + 1
End If
Loop
i = i + 1
orgnr1 = Sheets("Sheet1").Cells(i, 1).Value
Loop
I think that you must reset the variable j, so I add j = 0 in your code.
According to Siddharth Rout if orgnr1 not set then orgnr1 = Sheets("Sheet1").Cells(i, 1).Value
Do
If orgnr1 = "" Then Exit Sub
Do
orgnr2 = Sheets("edi_partnere").Cells(j, 1).Value
If orgnr2 = orgnr1 Then
Sheets("Sheet1").Cells(j, 9).Value = "-1" 'not happening
Exit Do
ElseIf orgnr2 = "" Then
Sheets("Sheet1").Cells(j, 9).Value = "0" 'not happening
Exit Do
Else: j = j + 1
End If
Loop
j = 0
i = i + 1
orgnr1 = Sheets("Sheet1").Cells(i, 1).Value
Loop

Resources