0

I using comment entry using VBA + Excel. Error occurring in this loop is pretty expected so i put On error Resume Next. if error occurs, the whole row will be colored in red.

But i found problem with code.. if error occurs, not only the row with error but also the next row without automatically are colored in red.

bot.Wait 1000

lastRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row

For X = 2 To lastRow

    bot.Wait 1000
    
    
    bot.FindElementById("headerForm:awbSearchText", 3000).SendKeys Sheet1.Cells(X, 1)
    
    bot.Wait 1000
    
    bot.FindElementById("headerForm:searchBtnHidden", 3000).Click


'Update Activity

    bot.Wait 2500
    
    Dim eleAct As SelectElement
        Set eleAct = bot.FindElementById("headerForm:menuItems").AsSelect
        eleAct.SelectByText "Update Activity"
    
    bot.FindElementById("headerForm:goButton", 3000).Click
    

'Comment update & save

    bot.Wait 2500
    
    Dim eleAct2 As SelectElement
        Set eleAct2 = bot.FindElementById("tabview:tabform:updateActivitySubView:updateActivityPanel:updateActivity:updateTypeCode", 3000).AsSelect
        eleAct2.SelectByText "Other"
        
    bot.Wait 2500
    
    
    bot.FindElementByXPath("//textarea[@name='tabview:tabform:updateActivitySubView:updateActivityPanel:updateActivity:j_id_id84pc14']", 3000).SendKeys Sheet1.Cells(X, 2)
    
    bot.Wait 3000
    
    bot.FindElementById("tabview:tabform:updateActivitySubView:updateActivityPanel:updateActivity:save", 3000).Click
    
    bot.Wait 2000


    bot.FindElementByXPath("//*[@id='tabview:j_id_id62:0:tabName']").Click

    If Err.Number > 0 Then
    
    Sheet1.Cells(X, 1).EntireRow.Font.Color = vbRed
    
    End If
    
    bot.Wait 1500
Next 
HTKIM
  • 25
  • 2
  • 8
  • 1
    `Err` needs to be reseted after checking or it will stay as it is (unless a new one occures) and the rest of the loop will change color. Read [Error Handling in VBA](https://stackoverflow.com/a/1046222/9439330) ! If you provide more infos what website is scrapes, you may get suggestions for better alternatives. – ComputerVersteher Sep 27 '20 at 05:21
  • `Sheet1.Cells(X, 1).EntireRow.Font.Color = vbRed` here eg. for X=2 and error occurred you coloring the entire X=2 row, so obviously this will color the entire row. use `Sheet1.Cells(X, 1).Font.Color = vbRed' to color the `column 1` in `Row X`. – Dilip Meghwal Sep 27 '20 at 05:27
  • Sorry guys, i had typo. It is not column which had the problem, i was row. – HTKIM Sep 27 '20 at 05:37
  • Plus, coloring entire row is not a problem. Problem is the next row without error is being colored if previous row had the error... – HTKIM Sep 27 '20 at 05:38
  • Thank you for the resetting error option. I going to check it on the article and get back to you! – HTKIM Sep 27 '20 at 05:38

1 Answers1

1

Error numbers can be negative or positive.

Use

If Err.number <> 0 Then

TinMan
  • 6,624
  • 2
  • 10
  • 20
  • Thank you for your comment. But problem got worse.. if i changed as you advised but now if error occurs on one column, following columns are colored in red though there is no error on following columns. – HTKIM Sep 27 '20 at 05:05