I need a bit of advice

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
Hi
FOR INFO ONLY - I have placed all three rows of code together for you viewing, normally they all are in their own IF statement.

I need a bit of advice, looking at the code below. I can not see any difference, however I am having an issue with this code for column B ONLY see image. Column B is empty there are no hidden items in it and there is nothing in the code that states that column B should START at one down.
VBA Code:
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "A").End(xlUp).Row + 1, "A").Offset(y, 0).Value = HtmlText
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "B").End(xlUp).Row + 1, "B").Offset(y, 0).Value = HtmlText
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "C").End(xlUp).Row + 1, "C").Offset(y, 0).Value = HtmlText
1586440503306.png


As you can see it does not put the data into the right place for column B ONLY all other column data is fine.

If I change the code to this:
VBA Code:
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "A").End(xlUp).Row + 1, "A").Offset(y, 0).Value = HtmlText
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "A").End(xlUp).Row + 1, "B").Offset(y, 0).Value = HtmlText
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "C").End(xlUp).Row + 1, "C").Offset(y, 0).Value = HtmlText
Then the problem fixes itself.
1586440770875.png

I guess my question are
  • WHY is this happening for COLUMN B only?
  • And how should the code be written?
Should it be LIKE this for ALL of the columns
VBA Code:
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "A").End(xlUp).Row + 1, "A").Offset(y, 0).Value = HtmlText
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "A").End(xlUp).Row + 1, "B").Offset(y, 0).Value = HtmlText
wsSheet.Cells(Sheet3.Cells(Sheet3.Rows.Count, "A").End(xlUp).Row + 1, "C").Offset(y, 0).Value = HtmlText

I have a rough idea of what the code is doing, could someone break it down with comments so i know what each part of the code is doing.

Thanks in advance
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Sorry I forgot to include these

VBA Code:
y = 0
    Set Html = objIE.document
        Set elements = Html.getElementsByClassName("sresult lvresult clearfix li shic")
    
For Each element In elements

Dim wsSheet As Worksheet
Dim wb As Workbook
Dim HtmlText As Variant
    Set wb = ThisWorkbook
         Set wsSheet = wb.Sheets("Sheet3")

And


VBA Code:
y = y + 1
Next element
 
Upvote 0
can anyone advise on this, please.
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

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