gpt4 book ai didi

excel - 选择行数可变的列中的所有数据

转载 作者:行者123 更新时间:2023-12-04 19:59:22 26 4
gpt4 key购买 nike

我有一个示例,我想编写一个 VBA 语句,它将选择单个列中的所有数据,列数据中没有空格。列位置永远不会改变,例如A 列,数据从第 3 行开始。但是,该列中的总行数会定期变化。

我希望系统动态选择列中的所有单元格,然后我可以针对这些选定的数据运行一个方法。

最佳答案

作为对范围执行操作而不选择它的示例:

Public Sub Test()

Dim rColA As Range

With ThisWorkbook.Worksheets("Sheet1")
Set rColA = .Range(.Cells(3, 1), .Cells(.Rows.Count, 1).End(xlUp))
MsgBox "Column A range is " & rColA.Address 'Delete if you want.

rColA.Interior.Color = RGB(255, 0, 0) 'Turn the back colour red.

rColA.Cells(2, 1).Insert Shift:=xlDown 'Insert a blank row at second cell in range
'So will insert at A4.

'If the first cell in your range is a number then double it.
If IsNumeric(rColA.Cells(1, 1)) Then
rColA.Cells(1, 1) = rColA.Cells(1, 1) * 2
End If

End With

End Sub

关于excel - 选择行数可变的列中的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44307359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com