我有一個函數可以解析文本和單元格的值,爲HTML表格創建代碼。Excel範圍循環變量的名稱
這裏是我的代碼:
Function Html(Rng1 As Range, Rng2 As Range, Head As Boolean) As String
' this function will take columns of data and properly format them for html table
Dim retVal As String
Dim i, j, p As Integer
p = 1
'if ranges doesn't contains one column and same rows count - return #VALUE error
If Rng1.Rows.count <> Rng2.Rows.count Or _
Rng1.Columns.count <> 1 Or Rng2.Columns.count <> 1 Then
Html = CVErr(xlErrValue)
Exit Function
End If
retVal = ""
For j = 1 To 2
If Head = True Then
retVal = retVal & "<th>" & Rng1.Cells(1, j)& "</th>"
If j = 2 Then
retVal = retVal & "<th>" & Rng2.Cells(1, j) & "</th>"
End If
p = 2
End If
retVal = retVal & "<tr>"
For i = p To Rng1.Rows.count
retVal = retVal & "<td>" & Rng & j & .Cells(i, 1) & "</td>"
Next i
retVal = retVal & "</tr>"
Next j
Html = "<table>" & retVal & "</table>"
End Function
問題是我通過兩個範圍要循環。範圍被稱爲Rng1
和Rng2
。我想結合:?RNG」和循環標識符j
使Rng1.Cells(i,1)
但因爲它是在該對象的中間我不知道如何將它結合
任何幫助
你試圖把並排的兩個範圍的部分,在一個HTML表?換句話說 - 你想要逐行處理它們嗎? – Floris
是的,兩行數據是我之後的 – Crimpy