getting stuck with this code - can someone have look

Rohith1324

Board Regular
Joined
Feb 27, 2018
Messages
114
Hi,

I have the below code but getting stuck on the code highlighted below : ( Red )

can someone pls suggest what is wrong here.

bot.Start "Chrome", "??"
bot.Window.Maximize
bot.Get "??"
bot.Wait 2000
bot.FindElementByXPath("//*[@id='unamebean']").SendKeys ActiveSheet.Range("B1").Value
bot.FindElementByXPath("//*[@id='pwdbean']").SendKeys ActiveSheet.Range("B3").Value
bot.FindElementByXPath("//*[@id='SubmitButton']").Click
bot.FindElementByXPath("//*[@id='AppsNavLink']").Click
bot.Timeouts.PageLoad = 90000
bot.FindElementByXPath("//*[@id='ILS_POS_PMENTS']").Click
bot.FindElementByXPath("//*[@id='ILS_POS_ASN_SELECT_TASK']").Click
bot.FindElementByLinkText("Create Advance Notices/Service Note").Click
bot.FindElementByXPath("//*[@id='AdvSearchBtn']").Click
For Each C In Range("A6:A" & Cells(Rows.Count, "A").End(xlUp).Row).Cells
bot.Timeouts.PageLoad = 90000
OName = C.Offset(0, 0).Value
Debug.Print OName
DoEvents
bot.Wait 500
bot.FindElementByXPath("//*[@id='Value_0']").SendKeys C.Offset(0, 0).Value
bot.Wait 200
bot.FindElementByXPath("//*[@id='AdvSearch']/table[3]/tbody/tr[9]/td[4]/button[1]").Click
Set np = bot.FindElementByXPath("//*[@id='STable']/table/tbody/tr/td/table/tbody/tr[2]/td[2]")
C.Offset(0, 42).Value = np.Text
If IsEmpty(C.Offset(0, 43).Value) = True Then
C.Offset(0, 44).Value = "Can not be processed"
Next C ‘Getting stuck here
Else
C.Offset(0, 44).Value = "Processing"
End If
R = 1
Set rsecs = bot.FindElementsByClass("xaq")
For Each rsec In rsecs
R = R + 1
Sheets("Sheet2").Cells(R, 2).Value = rsec.Text
Next rsec
bot.FindElementByXPath("//*[@id='PosAsnAddToCart']").Click
bot.FindElementByXPath("//*[@id='N317:AddAttach:0']/a/img").Click
bot.FindElementByXPath("//*[@id='FileName']").SendKeys C.Offset(0, 1).Value
bot.FindElementByXPath("//*[@id='FileInput_oafileUpload']").SendKeys C.Offset(0, 2).Value
bot.FindElementByXPath("//*[@id='Okay_uixr']").Click
Next C
MsgBox "Macro is done till this level, your inputs requried to proceed further"
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Shouldn't your "Next C" be after the "End If", not right in the middle of your if statement ?
 
Upvote 0
Hi Alex,

Actually I wanted code to move to next C when the IF value statement is not fullfilling the requirement.

I dont want other steps to be processed if IF statement is True.

Could you please suggest how to modify this.


Shouldn't your "Next C" be after the "End If", not right in the middle of your if statement ?
 
Upvote 0
Hi Alex,

Actually I wanted code to move to next C when the IF value statement is not fullfilling the requirement.

I dont want other steps to be processed if IF statement is True.

Could you please suggest how to modify this.
Just get rid of the first Next C and place the rest of the code to be actioned inside the "Else" part of the "If statement"

VBA Code:
    For Each C In Range("A6:A" & Cells(Rows.Count, "A").End(xlUp).Row).Cells
        bot.Timeouts.PageLoad = 90000
        OName = C.Offset(0, 0).Value
        Debug.Print OName
        DoEvents
        bot.Wait 500
        bot.FindElementByXPath("//*[@id='Value_0']").SendKeys C.Offset(0, 0).Value
        bot.Wait 200
        bot.FindElementByXPath("//*[@id='AdvSearch']/table[3]/tbody/tr[9]/td[4]/button[1]").Click
        Set np = bot.FindElementByXPath("//*[@id='STable']/table/tbody/tr/td/table/tbody/tr[2]/td[2]")
        C.Offset(0, 42).Value = np.Text

        If IsEmpty(C.Offset(0, 43).Value) = True Then
            C.Offset(0, 44).Value = "Can not be processed"
        Else
            C.Offset(0, 44).Value = "Processing"
            R = 1
            Set rsecs = bot.FindElementsByClass("xaq")

            For Each rsec In rsecs
                R = R + 1
                Sheets("Sheet2").Cells(R, 2).Value = rsec.Text
            Next rsec

            bot.FindElementByXPath("//*[@id='PosAsnAddToCart']").Click
            bot.FindElementByXPath("//*[@id='N317:AddAttach:0']/a/img").Click
            bot.FindElementByXPath("//*[@id='FileName']").SendKeys C.Offset(0, 1).Value
            bot.FindElementByXPath("//*[@id='FileInput_oafileUpload']").SendKeys C.Offset(0, 2).Value
            bot.FindElementByXPath("//*[@id='Okay_uixr']").Click
        End If

    Next C

    MsgBox "Macro is done till this level, your inputs requried to proceed further"
 
Upvote 0
Solution
Thank you Alex...It worked as i was expecting...
Just get rid of the first Next C and place the rest of the code to be actioned inside the "Else" part of the "If statement"

VBA Code:
    For Each C In Range("A6:A" & Cells(Rows.Count, "A").End(xlUp).Row).Cells
        bot.Timeouts.PageLoad = 90000
        OName = C.Offset(0, 0).Value
        Debug.Print OName
        DoEvents
        bot.Wait 500
        bot.FindElementByXPath("//*[@id='Value_0']").SendKeys C.Offset(0, 0).Value
        bot.Wait 200
        bot.FindElementByXPath("//*[@id='AdvSearch']/table[3]/tbody/tr[9]/td[4]/button[1]").Click
        Set np = bot.FindElementByXPath("//*[@id='STable']/table/tbody/tr/td/table/tbody/tr[2]/td[2]")
        C.Offset(0, 42).Value = np.Text

        If IsEmpty(C.Offset(0, 43).Value) = True Then
            C.Offset(0, 44).Value = "Can not be processed"
        Else
            C.Offset(0, 44).Value = "Processing"
            R = 1
            Set rsecs = bot.FindElementsByClass("xaq")

            For Each rsec In rsecs
                R = R + 1
                Sheets("Sheet2").Cells(R, 2).Value = rsec.Text
            Next rsec

            bot.FindElementByXPath("//*[@id='PosAsnAddToCart']").Click
            bot.FindElementByXPath("//*[@id='N317:AddAttach:0']/a/img").Click
            bot.FindElementByXPath("//*[@id='FileName']").SendKeys C.Offset(0, 1).Value
            bot.FindElementByXPath("//*[@id='FileInput_oafileUpload']").SendKeys C.Offset(0, 2).Value
            bot.FindElementByXPath("//*[@id='Okay_uixr']").Click
        End If

    Next C

    MsgBox "Macro is done till this level, your inputs requried to proceed further"
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top