How to run the next statement if the cell value is blank in EXCEL VBA

vikneshwar

New Member
Joined
Sep 10, 2012
Messages
9
I Have a requirement to fill a web form using VBA. In a input data sheet Column F,G,H has few cell are blank.
I want to skip those blank cells and move to next statement without showing any error.
I have mentioned the VBA SCRIPT which I have created.

If someone help me to fix this i will feel very glad.

From the following I want to skip the blank cells and go for next statement. Column ( F, G, H)
Snap5.JPG

VBA Code:
Sub copy_project_loop()

Dim IE As Object
Dim Doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
Dim SHELL_OBJECT
SHELL_OBJECT = "WScript.Shell"
Set objShell = CreateObject(SHELL_OBJECT)


IE.Visible = True
IE.navigate "[URL='https://www.*******?CSTK=Y']Login[/URL]"

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
  
    Set Doc = IE.document
  
    ' Set numrows = number of rows of data.
      NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
  
      ' Establish "For" loop to loop "numrows" number of times.
      For intRow = 2 To NumRows

    Doc.getElementById("txtTimeStudyNbr").Value = ThisWorkbook.Sheets("data").Range("A" & intRow).Value
    Doc.getElementById("Search").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("E1").Value
    Doc.getElementById("Search").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifiers").Value = [COLOR=rgb(85, 57, 130)][B]ThisWorkbook.Sheets("data").Range("E" & intRow).Value[/B][/COLOR]
    Doc.getElementById("ADD").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("F1").Value
    Doc.getElementById("Search").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifiers").Value = [COLOR=rgb(85, 57, 130)][B]ThisWorkbook.Sheets("data").Range("F" & intRow).Value[/B][/COLOR]
    Doc.getElementById("ADD").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("G1").Value
    Doc.getElementById("Search").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifiers").Value = [B][COLOR=rgb(85, 57, 130)]ThisWorkbook.Sheets("data").Range("G" & intRow).Value[/COLOR][/B]
    Doc.getElementById("ADD").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("H1").Value
    Doc.getElementById("Search").Click
  
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
  
    Doc.getElementById("lstQualifiers").Value = [COLOR=rgb(85, 57, 130)][B]ThisWorkbook.Sheets("data").Range("H" & intRow).Value[/B][/COLOR]
    Doc.getElementById("ADD").Click

Next

End Sub
 
Last edited by a moderator:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

vikneshwar

New Member
Joined
Sep 10, 2012
Messages
9
I Have a requirement to fill a web form using VBA. In a input data sheet Column F,G,H has few cell are blank.
I want to skip those blank cells and move to next statement without showing any error.
I have mentioned the VBA SCRIPT which I have created.

If someone help me to fix this i will feel very glad.

From the following I want to skip the blank cells and go for next statement. Column ( F, G, H)
View attachment 12847
VBA Code:
Sub copy_project_loop()

Dim IE As Object
Dim Doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
Dim SHELL_OBJECT
SHELL_OBJECT = "WScript.Shell"
Set objShell = CreateObject(SHELL_OBJECT)


IE.Visible = True
IE.navigate "[URL='https://www.gslts.ford.com/TimeStudy/Qualifier.asp?CSTK=Y']Login[/URL]"

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop


    Set Doc = IE.document

    ' Set numrows = number of rows of data.
      NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count

      ' Establish "For" loop to loop "numrows" number of times.
      For intRow = 2 To NumRows

    Doc.getElementById("txtTimeStudyNbr").Value = ThisWorkbook.Sheets("data").Range("A" & intRow).Value
    Doc.getElementById("Search").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("E1").Value
    Doc.getElementById("Search").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifiers").Value = [COLOR=rgb(85, 57, 130)][B]ThisWorkbook.Sheets("data").Range("E" & intRow).Value[/B][/COLOR]
    Doc.getElementById("ADD").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("F1").Value
    Doc.getElementById("Search").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifiers").Value = [COLOR=rgb(85, 57, 130)][B]ThisWorkbook.Sheets("data").Range("F" & intRow).Value[/B][/COLOR]
    Doc.getElementById("ADD").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("G1").Value
    Doc.getElementById("Search").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifiers").Value = [B][COLOR=rgb(85, 57, 130)]ThisWorkbook.Sheets("data").Range("G" & intRow).Value[/COLOR][/B]
    Doc.getElementById("ADD").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifierTypes").Value = ThisWorkbook.Sheets("data").Range("H1").Value
    Doc.getElementById("Search").Click

    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    Doc.getElementById("lstQualifiers").Value = [COLOR=rgb(85, 57, 130)][B]ThisWorkbook.Sheets("data").Range("H" & intRow).Value[/B][/COLOR]
    Doc.getElementById("ADD").Click

Next

End Sub
I Dont want to colour the cells . I have highlighted the cell for your reference. Actually my requirement is ,If the cell value is blank then it needs to go for next statement. For example if the column "E" is blank then skip that and go for Column "F" statements... it continues for other column.
 

vikneshwar

New Member
Joined
Sep 10, 2012
Messages
9
I Dont want to colour the cells . I have highlighted the cell for your reference. Actually my requirement is ,If the cell value is blank then it needs to go for next statement. For example if the column "E" is blank then skip that and go for Column "F" statements... it continues for other column.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,175
Messages
5,640,607
Members
417,156
Latest member
Ciupanezul21

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
Top