![](/img/trans.png)
[英]excel macro: for each cell with a value in a row, insert a row below with that value
[英]Excel vba for each visible cell in A row, insert value in H row ?
如何使用vba根據excel中A行的可見性狀態在H行中插入值?
Dim rng As Range
Set rng = Range("A2", Range("A65536").End(xlUp)).SpecialCells(xlCellTypeVisible)
For Each cell In rng
rng.value = "Something"
Next cell
上面的代碼將“內容”填充到A行,但是我不知道如何將其映射到H行(在哪里)? 有人有想法么...
您可以使用迭代中每個cell
的Row
屬性映射到H列中的正確行
Sub Macro1()
Dim rng As Range
Set rng = Range("A2", Range("A65536").End(xlUp)).SpecialCells(xlCellTypeVisible)
For Each cell In rng
Range("H" & cell.Row).Value = "Something"
Next cell
End Sub
如果每行的值相同,則不需要循環:
Sub NoLoop()
Dim r As Range
Set r = Range("H2:H" & Cells(Rows.Count, "H").End(xlUp).Row)
Set r = r.Cells.SpecialCells(xlCellTypeVisible)
r.Value = "whatever"
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.