Need Help on an IF statement

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,054
Office Version
  1. 2016
Platform
  1. Windows
How can I write this, as currently it is giving me just the word "None" even if there is data. In short if there is innertext to extract, extract it if there is nothing then place "None" in the cell

VBA Code:
              If dd = doc.getElementsByClassName("_50f4")(2) Is Nothing Then
                          wsSheet.Cells(Sheet1.Cells(Sheet1.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = "None"
                Else
                      dd = doc.getElementsByClassName("_50f4")(2).innerText
                              Sheet1.Cells(Sheet1.Cells(Sheet1.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = dd
               End If
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,054
Office Version
  1. 2016
Platform
  1. Windows
I think its this, have tested it and it does seem to do the job, has pulled off a few whrong things but I will have to check the class element child layout to see if I got it wrong or the code is wrong.

Until I think it this, if any one can improve please do so.

VBA Code:
     If doc.getElementsByClassName("_50f4")(2) Is Nothing Then
            wsSheet.Cells(Sheet1.Cells(Sheet1.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = "NIL"
      Else
            dd = doc.getElementsByClassName("_50f4")(2).innerText
               Sheet1.Cells(Sheet1.Cells(Sheet1.Rows.Count, "B").End(xlUp).Row + 1, "B").Value = dd
      End If
 

Watch MrExcel Video

Forum statistics

Threads
1,129,404
Messages
5,636,083
Members
416,897
Latest member
YAFI

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