I have 8 comboboxes on a form that I wish to populate with saved values when the user opts to do so.
The problem I have is that although the code all works only the first combobox actually updates - unless I call the sub twice (i.e the user simply clicks the command button again) and then all comboboxes populate perfectly.
It's not complex code (at all) but clearly there is something I'm missing - I'm not sure why the comboboxes all update the second time the sub is run but not the first. Any ideas?
Dim loadlimit
Dim loadrow
Dim loadprev As Boolean
Dim l(8) As String
Dim i
i = 1
loadrow = 1
loadprev = False
loadlimit = lastrow(Sheet19)
Do Until loadrow > loadlimit
If Cells(loadrow, 1).Value = geogselect.selectedind.Value Then
loadprev = True
l(1) = Cells(loadrow, 2).Value
l(2) = Cells(loadrow, 3).Value
l(3) = Cells(loadrow, 4).Value
l(4) = Cells(loadrow, 5).Value
l(5) = Cells(loadrow, 6).Value
l(6) = Cells(loadrow, 7).Value
l(7) = Cells(loadrow, 8).Value
l(8) = Cells(loadrow, 9).Value
geogselect.ComboBox1.Text = l(1)
geogselect.ComboBox2.Text = l(2)
geogselect.ComboBox3.Text = l(3)
geogselect.ComboBox4.Text = l(4)
geogselect.ComboBox5.Text = l(5)
geogselect.ComboBox6.Text = l(6)
geogselect.ComboBox7.Text = l(7)
geogselect.ComboBox8.Text = l(8)
End If
loadrow = loadrow + 1
Loop
Thanks in hope!
Thanks for all the assistance, telling Excel to setFocus before updating each combobox resolved this.
Related
I was trying to make some cell spaces in Excel for every time Saved Invoices that go into record sheet.
But instead the last cell of item and Qty get overwritten by new save
And it didn't go as a whole one(1) order if I try to sort it from individual table.
Also, I didn't know how or what's the problem or solution that I can type to search the Google
Was trying to make something like this
example
Sub Save()
Dim SimpanInvoice As Object
Set SimpanInvoice = Sheet3.Range("A20000").End(xlUp)
If Sheet4.Range("Invonomer").Value = "" _
Or Sheet4.Range("Invotgl").Value = "" _
Or Sheet4.Range("Invoto").Value = "" _
Or Sheet4.Range("Invoalamat").Value = "" Then
Call MsgBox("Harap isi data dengan lengkap", vbInformation, "Isi Data")
Else
SimpanInvoice.Offset(1, 0).Value = Sheet4.Range("Invonomer").Value
SimpanInvoice.Offset(1, 1).Value = Sheet4.Range("Invotgl").Value
SimpanInvoice.Offset(1, 2).Value = Sheet4.Range("Invoto").Value
SimpanInvoice.Offset(1, 3).Value = Sheet4.Range("Invoalamat").Value
SimpanInvoice.Offset(1, 4).Value = Sheet4.Range("Keterangan").Value
SimpanInvoice.Offset(1, 5).Value = Sheet4.Range("item1").Value
SimpanInvoice.Offset(1, 6).Value = Sheet4.Range("Qty_1").Value
SimpanInvoice.Offset(2, 5).Value = Sheet4.Range("item2").Value
SimpanInvoice.Offset(2, 6).Value = Sheet4.Range("Qty_2").Value
Call MsgBox("Data SuratTagihan Telah Di Simpan", vbInformation, "Data Surat Tagihan")
Sheet4.Range("Invonomer").Value = ""
Sheet4.Range("Invotgl").Value = ""
Sheet4.Range("Invoto").Value = ""
Sheet4.Range("Invoalamat").Value = ""
Sheet4.Range("Keterangan").Value = ""
Sheet4.Range("item1").Value = ""
Sheet4.Range("Qty_1").Value = ""
Sheet4.Range("item2").Value = ""
Sheet4.Range("Qty_2").Value = ""
End If
End Sub
here is full code that I've been trying
Your ColA is not fully populated, so you could add a loop to make sure the row you're working on is empty
Dim SimpanInvoice As Object
Set SimpanInvoice = Sheet3.Range("A20000").End(xlUp).Offset(1)
'make sure the row we're on is completely empty (not just empty in ColA)
Do While Application.CountA(SimpanInvoice.EntireRow) > 0
Set SimpanInvoice = SimpanInvoice.Offset(1) 'next row down
Loop
'start populating the row
SimpanInvoice.Value = Sheet4.Range("Invonomer").Value
SimpanInvoice.Offset(0, 1).Value = Sheet4.Range("Invotgl").Value
'etc etc
I am working on a scrip that creates Sales Orders in SAP's VA01 - Order Creation, DEP - Production environment.
All of the information is drawn from the Excel file where the macro is stored. These are the two issues I am facing at the moment:
If I declare variables I get the Run-time error 13: mismatch error in the very beginning of the code.
I solved this by typing directly into the script the type of order I am creating at the moment. However, I would like to declare the variables for these as the type may change in the future. I attempted to use the variables declared, and also a cell reference. The script leaves the fields in blank.
Here is that section of the script:
'Order creation set up
session.StartTransaction "va01"
session.findById("wnd[0]/usr/ctxtVBAK-AUART").Text = "YKE" 'ws.Cells(3, 14).Value 'OrderType
session.findById("wnd[0]/usr/ctxtVBAK-VKORG").Text = "CE01" 'ws.Cells(4, 14).Value 'SalesOrg
session.findById("wnd[0]/usr/ctxtVBAK-VTWEG").Text = "10" 'ws.Cells(5, 14).Value 'DistChan
session.findById("wnd[0]/usr/ctxtVBAK-SPART").Text = "10"
session.findById("wnd[0]").sendVKey 0
I get the Run-time error 619: control could not be found by ID.
This happens in this section of the script, precisely in the line Condition and ConditionVal:
'Entering the header for the Condition Type and Condition Type Value
'session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,1]").SetFocus
'session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,1]").caretPosition = 0
session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/btnBT_HEAD").press
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05").Select
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/subSUBSCREEN_PUSHBUTTONS:SAPLV69A:1000/btnBT_KOAN").press
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/ctxtKOMV-KSCHL[1,1]").Text = Condition 'ws.Cells(i, 10).Value
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,1]").Text = ws.Cells(i, 11).Value 'ConditionVal
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,1]").SetFocus
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,1]").caretPosition = 16
session.findById("wnd[0]").sendVKey 11
To me it does not make sense, as in a previous section of the script the variables were declared and used without inconvenients. For what I gather, the issues here are the variables declarations.
When I use the variables declared the fields again stay blank.
I have tried using Long, String, and Variants, however no luck. Can someone suggest an option? Has someone faced this issue in the past and managed to overcome it?
Here is the full code, as well as a print screen of the Excel file for references:
Sub BROrderCreation()
Dim ws As Worksheet
Dim i As Long
Dim maxi As String
Dim lastRow As Long
'On Error GoTo PopUpHandler
Set GuiAuto = GetObject("SAPGUI") 'Get the SAP GUI Scripting object
Set App = GuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set Con = App.Children(0) 'Get the first system that is currently connected
Set session = Con.Children(0) 'Get the first session (window) on that connection
Set sessioninfo = session.Info
'Declare variables for the order type, sales organization, distribution chanel and division
Dim OrderType As String
Dim SalesOrg As String
Dim DistChan As Byte
Dim Div As Byte
Set ws = Excel.ThisWorkbook.Worksheets("PO Data")
OrderType = ws.Cells(3, 14).Value
SalesOrg = ws.Cells(4, 14).Value
DistChan = ws.Cells(5, 14).Value
Div = ws.Cells(6, 14).Value
'Order creation set up
session.StartTransaction "va01"
session.findById("wnd[0]/usr/ctxtVBAK-AUART").Text = "YKE" 'ws.Cells(3, 14).Value 'OrderType
session.findById("wnd[0]/usr/ctxtVBAK-VKORG").Text = "CE01" 'ws.Cells(4, 14).Value 'SalesOrg
session.findById("wnd[0]/usr/ctxtVBAK-VTWEG").Text = "10" 'ws.Cells(5, 14).Value 'DistChan
session.findById("wnd[0]/usr/ctxtVBAK-SPART").Text = "10"
session.findById("wnd[0]").sendVKey 0
i = 2
maxi = ws.Cells(Rows.Count, 1).End(xlUp).Row
Do While i < maxi + 1
'Declare variables for Ship To, PO, RDD, SKU, QTY, Plant, Batch, Condition and Condition Value
Dim ShipTo As Variant
Dim PO As Variant
Dim RDD As Variant
Dim SKU As String
Dim QTY As String
Dim Plant As Variant
Dim Batch As Variant
Dim Condition As String
Dim ConditionVal As String
ShipTo = Cells(i, 1).Value
PO = Cells(i, 2).Value
RDD = Cells(i, 3).Value
SKU = Cells(i, 4).Value
QTY = Cells(i, 5).Value
Plant = Cells(i, 6).Value
Batch = Cells(i, 7).Value
Condition = Cells(i, 10).Value
ConditionVal = Cells(i, 11).Value
session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/txtVBKD-BSTKD").Text = PO
session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:SAPMV45A:4701/ctxtKUWEV-KUNNR").Text = ShipTo
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/ctxtRV45A-KETDAT").Text = RDD
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,0]").Text = SKU
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/txtRV45A-KWMENG[2,0]").Text = QTY
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-WERKS[3,0]").Text = Plant
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-CHARG[9,0]").Text = Batch
'session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-CHARG[9,0]").SetFocus
'session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtVBAP-CHARG[9,0]").caretPosition = 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0 'To cover the process in case the PO is already created
'Entering the header for the Condition Type and Condition Type Value
'session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,1]").SetFocus
'session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4401/subSUBSCREEN_TC:SAPMV45A:4900/tblSAPMV45ATCTRL_U_ERF_AUFTRAG/ctxtRV45A-MABNR[1,1]").caretPosition = 0
session.findById("wnd[0]/usr/subSUBSCREEN_HEADER:SAPMV45A:4021/btnBT_HEAD").press
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05").Select
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/subSUBSCREEN_PUSHBUTTONS:SAPLV69A:1000/btnBT_KOAN").press
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/ctxtKOMV-KSCHL[1,1]").Text = Condition 'ws.Cells(i, 10).Value
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,1]").Text = ws.Cells(i, 11).Value 'ConditionVal
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,1]").SetFocus
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\05/ssubSUBSCREEN_BODY:SAPLV69A:6201/tblSAPLV69ATCTRL_KONDITIONEN/txtKOMV-KBETR[3,1]").caretPosition = 16
session.findById("wnd[0]").sendVKey 11
'ZDEF screen accept and click on Invalid destination
session.findById("wnd[1]/usr/btnZACCEPT").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
Cells(i, 11) = "Placed"
i = i + 1
Loop
End Sub
The goal is that I have a second worksheet (CalcValues) with essentially lookup values (if fieldA = x, fieldB = y, fieldC = z, then value = a).
The skeleton of what I have (I don't work in VBA, so this may be wrong):
Dim calcArray
calcArray = Array(FIELDA, FIELDB, FIELDC, FIELDD, FIELDE)
If calcArray.Contains(Target.Column) Then
Dim fieldAVal, fieldBVal, fieldCVal, fieldDVal, fieldEVal
fieldAVal = Target.Worksheet.Cells(Target.Row, FIELDA)
...
fieldEVal = Target.Worksheet.Cells(Target.Row, FIELDE)
End If
With FIELDA-E being the lookup fields column indexes.
Not functional, but the goal is that if I set one of those fields a check is done, in pseudo-C# entity framework mixed in with what little I know from Excel's VBA something like:
var data = Worksheets("CalcValues").Where(c => c.ColumnA == fieldAVal);
data = data.Where(c => c.ColumnB == fieldBVal);
...
data = data.Where(c => c.ColumnE == fieldEVal);
' Ideally, grabbing a row number from data. Or row itself, either or.
' with GRABBED_ROW = the last remaining 'data' object's row number, provided one exists.
Target.Worksheet.Cells(Target.Row, UPDATEDFIELDA) = Worksheet("CalcValues").Cells(GRABBED_ROW, UPDATEDFIELDAINDEX);
Target.Worksheet.Cells(Target.Row, UPDATEDFIELDB) = Worksheet("CalcValues").Cells(GRABBED_ROW, UPDATEDFIELDBINDEX);
...
With the question being how do I achieve the filtering in the var data... data = data.Where(c => c.ColumnE == fieldEVal); section I pseudo coded?
edit: I'm doing some reviewing, but it looks like my best bet is to somehow have a dynamic array akin to a List in C#, and use Application.WorkSheet.Match to get there, would that be a correct?
edit2: Okay, I updated it (so can most likely ignore the 2nd section outside of seeing intent), but I'm not certain the code is correct (isn't firing):
For i = 1 To Worksheet("CalcValues").ListRows.Count
If (Worksheet("CalcValues").Cells(i, 1).Value = fieldAVal And Worksheet("CalcValues").Cells(i, 2).Value = fieldBVal And Worksheet("CalcValues").Cells(i, 3).Value = fieldCVal And Worksheet("CalcValues").Cells(i, 4).Value = fieldDVal And Worksheet("CalcValues").Cells(i, 5).Value = fieldEVal) Then
If (Worksheet("CalcValues").Cells(i, 6).Value = "Column A") Then
Target.Worksheet.Cells(Target.Row, COLUMNA).Value = Worksheet("CalcValues").Cells(i, 7).Value
ElseIf (Worksheet("CalcValues").Cells(i, 6).Value = "Column B") Then
Target.Worksheet.Cells(Target.Row, COLUMNB).Value = Worksheet("CalcValues").Cells(i, 7).Value
End If
End If
Next
Okay, I finally figured it out. A lot of assumptions were made on my part initially and come to find out it was quite a bit different functionally (perhaps there's a better way, but this seems to work):
Dim calcArray(1 To 5) As Integer
calcArray(1) = FIELDA
calcArray(2) = FIELDB
calcArray(3) = FIELDC
calcArray(4) = FIELDD
calcArray(5) = FIELDE
Dim it As Integer, found As Boolean
it = 1
Do While it <= UBound(calcArray) And Not found
If (calcArray(it) = Target.Column) Then
found = True
Else
it = it + 1
End If
Loop
If (found) Then
Dim fieldAVal, fieldBVal, fieldCVal, fieldDVal, fieldEVal
fieldAVal = Target.Worksheet.Cells(Target.Row, FIELDA)
fieldBVal = Target.Worksheet.Cells(Target.Row, FIELDB)
fieldCVal = Target.Worksheet.Cells(Target.Row, FIELDC)
fieldDVal = Target.Worksheet.Cells(Target.Row, FIELDD)
fieldEVal = Target.Worksheet.Cells(Target.Row, FIELDE)
For i = 1 To Worksheets("CalcValues").UsedRange.Rows.Count
If (Worksheets("CalcValues").Cells(i, 1).Value = fieldAVal And Worksheets("CalcValues").Cells(i, 2).Value = fieldBVal And Worksheets("CalcValues").Cells(i, 3).Value = fieldCVal And Worksheets("CalcValues").Cells(i, 4).Value = fieldDVal And Worksheets("CalcValues").Cells(i, 5).Value = fieldEVal) Then
If (Worksheets("CalcValues").Cells(i, 6).Value = "Column A") Then
Target.Worksheet.Cells(Target.Row, COLUMNA).Value = Worksheets("CalcValues").Cells(i, 7).Value
ElseIf (Worksheets("CalcValues").Cells(i, 6).Value = "Column B") Then
Target.Worksheet.Cells(Target.Row, COLUMNB).Value = Worksheets("CalcValues").Cells(i, 7).Value
End If
End If
Next
End If
OK so i have a combo box set up for:
With Pclient
Pclient.AddItem "CMN"
Pclient.AddItem "RSS"
Pclient.AddItem "ORD"
End With
When i select a option for Pclient, i want Pcodclient to be setup to X so it sets the value the client code without having to imput it manually.
Cells(ActiveCell.Row, 2).Value = Pclient.Value
Cells(ActiveCell.Row, 3).Value = Pcodclient.Value
How do i do this?
I tried running some
IF Pclient.Value = CMN then Pcodclient.Value = X
before the Cells part... but it doesn't work.
EDIT:
Dim Pcodclient As String
If Pclient.Value = "CMN" Then
Pcodclient.Value = "LSR000"
End If
If Pclient.Value = "RSS" Then
Pcodclient.Value = "LSR000"
End If
If Pclient.Value = "DEI" Then
Pcodclient.Value = "LSR041"
End If
If Pclient.Value = "CTD" Then
Pcodclient.Value = "LSR040"
End If
'in randul 1
Cells(ActiveCell.Row, 2).Value = Pclient.Value
Cells(ActiveCell.Row, 3).Value = Pcodclient.Value
Cells(ActiveCell.Row, 4).Value = Pptype.Value
I get a invalid qualifier on Pcodclient.Value = "LSR000"
how do i fix this?
I would recommend to create a Combobox by linking it to the cell (have a look here). Now use VLOOKUP to get the values from a table. It would mean that you don't have to do any VBA
Use the change event to update the Pcodclient
Private Sub Pclient_Change()
If Pclient.Value = "CMN" Then
Pcodclient = "X"
End If
If Pclient.Value = "RSS" Then
Pcodclient = "Y"
End If
If Pclient.Value = "ORD" Then
Pcodclient = "Y"
End If
End Sub
Private Sub NewMethod()
'Do something
End Sub
I am slowly building off this code as I'd like to learn VBA for future use. The purpose of this part of my code is to see if one cell's value is contained inside another sheet in the same workbook's cell. If this is true then I would like to mark column 10 of the same row in Worksheets("FDSA") as "ok" and write nothing if it is not.
Sub test1()
Dim Str As String
Dim Search As String
Str = Cells(2, 5).Value
Search = Worksheets("FDSA").Cells(2, 5).Value
If InStr(Search, Str) > 0 Then
Worksheets("FDSA").Cells(2, 10).Value = "ok"
End If
End Sub
I got an answer yesterday that helped a lot (top). I am now trying to make a loop for that code. Here it is now (bottom).
Sub test1()
For X = 2 To 5
For Y = 2 To 5
Dim Str As String
Dim Search As String
Str = Cells(X, 5).Value
Search = Worksheets("FDSA").Cells(Y, 5).Value
If InStr(Search, Str) > 0 Then
Worksheets("FDSA").Cells(Y, 10).Value = "ok"
Else
Worksheets("FDSA").Cells(Y, 10).Value = ""
End If
Next Y
Next X
End Sub
I ran a test to see if it worked and it did not. I made it so that cells(5,5) was not contained inside of Worksheets("FDSA").Cells(Y, 5) and it still wrote the ok. After doing some research I have concluded that the Dim storage might be the problem(It is using the value of the initials which due match).I tried using ReDim and clear but could not run the code. Thank you for your help, please let me know if you need more explanation.
-Alexis M.
I think you only want one loop:
Sub test1()
Dim Str As String
Dim Search As String
Dim X as Long
For X = 2 To 5
Str = Cells(X, 5).Value
Search = Worksheets("FDSA").Cells(X, 5).Value
If InStr(Search, Str) > 0 Then
Worksheets("FDSA").Cells(X, 10).Value = "ok"
Else
Worksheets("FDSA").Cells(X, 10).Value = ""
End If
Next X
End Sub