1
A
回答
3
怎麼樣;
'//get a range from anchor cell (a1) to the 1st empty cell in the same column;
dim r As Range, cell as Range
set r = Range(Range("A1"), Range("A1").End(xlDown))
'//loop it
for Each cell In r
msgbox cell.Value
next
+1
1)我不會使用單元格作爲變量名稱。稱它爲myCell。 2)你需要將'DIM myCell'作爲範圍' –
+1
添加一個暗淡的I剩餘單元格,它不是一個保留字,並且不會在xl對象模型中用作類名稱的任何地方(儘管Cells是) –
+0
感謝所有的答覆。 – joseph
0
在VBA中,基於細胞都可以用範圍來完成,使用偏移來回報你正在尋找的價值:
Dim Anchor as Range
Set Anchor = Range("A1")
i = 0
Do
' Cell in column is Anchor.Offset(0, i)
' i.e., Anchor.Offset(0, 0) = A1
' Anchor.Offset(0, 1) = B1
' Anchor.Offset(0, ") = C1
' etc.
' Do whatever you like with this, here!
i = i + 1
Loop Until Anchor.Offset(0, i) = ""
1
我調整AlexK的回答是:
dim c As Range
'//loop it
for Each c In Range(Range("A1"), Range("A1").End(xlDown))
msgbox c.Value
next
相關問題
- 1. 循環遍歷行和列Excel宏VBA
- 2. 如何從表頭中遍歷列vba
- 3. 在Excel VBA宏中,如何遍歷大量列?
- 4. Excel VBA - 讓VBA腳本遍歷行
- 5. Excel的VBA - 遍歷一個行
- 6. 如何遍歷Excel VBA或VSTO 2005中的所有單元格
- 7. VBA循環遍歷兩個excel列中的值
- 8. 如何在excel中循環遍歷行VBA宏
- 9. Excel VBA循環遍歷列和副本列
- 10. VBA excel:如何遍歷列和基於條件改變偏移列
- 11. Excel Vba循環遍歷行列的單元格
- 12. 如何循環遍歷VBA中的各個列
- 13. Excel VBA循環遍歷列和保存結果
- 14. 如何遍歷Excel VBA中自動過濾工作表中的行?
- 15. 循環遍歷Excel中的單元格值VBA
- 16. Excel中:試圖遍歷
- 17. 如何遍歷javascript中的列表
- 18. 如何遍歷ID列表
- 19. 在Excel中循環遍歷單元格VBA
- 20. VBA遍歷單元格
- 21. Excel VBA循環遍歷單元格並替換它們的值
- 22. C++中的遍歷隊列
- 23. 遍歷javascript中的列表
- 24. 遍歷列中的值
- 25. 遍歷dplyr中的列?
- 26. 如何遍歷列表視圖列
- 27. 遍歷列,
- 28. 遍歷列表
- 29. 遍歷陣列
- 30. 遍歷DataGridViewRow列
雖然這被標記爲回答一旦範圍被定義,你想要對列做什麼? – brettdj
我正在使用Cognos TM1,並且需要從OLAP獲得對單元格的註釋 – joseph