0

I want the below function to pick data from Row till Column H, however this function is picking details up to the last used cell.

Below are the VBA code I'm using, help me to fix this.

Function getapproverdataHTML() As String

    Dim datacolumn As Range
    Dim datarow As Range
    Dim R As Range
    Dim C As Range
    Dim str As String

    sheets(2).Activate

    Set datacolumn = Range("A1", Range("A1").End(xlDown))

    str = "<table>"

    For Each R In datacolumn
    str = str & "<tr>"
    Set datarow = Range(R, R.End(xlToRight))
    For Each C In datarow
    str = str & "<td>" & C.Value & "</td>"
    Next C
    str = str & "</tr>"
    Next R
    str = str & "</table>"
    getapproverdataHTML = str


End Function
Rajesh Sinha
  • 9,403
PCH
  • 1

1 Answers1

0

If, by cell "H", you really mean the cell in column "H", then try changing your Set datarow line to:

Set datarow = Range(R, R(1, 9).End(xlToLeft))

If you mean something else, please clarify.

BTW, you should use a similar method for datacolumn

Set datacolumn = Range("A1", cells(rows.count,1).End(xlup))