A行中每个可见单元格的Excel vba,在H行中插入值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28609977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel vba for each visible cell in A row, insert value in H row ?
提问by Sabelo Ngcobo
How do I insert value in the H row based on the visibility status of A row in excel using vba?
如何使用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
The code above will populate 'something' to A row, but I don't know how to map this to H row (where) I want it ? Anyone have any ideas...
上面的代码会将“某物”填充到 A 行,但我不知道如何将其映射到我想要的 H 行(哪里)?谁有想法...
回答by chancea
You can use the Row
property of each cell
in your iteration to map to the correct row in column H
您可以在迭代中使用Row
each的属性cell
映射到 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
回答by Gary's Student
If its the same value for each row, you do not need a loop:
如果每行的值相同,则不需要循环:
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