gpt4 book ai didi

vba - 我需要能够通过在 vba 中指定列号来选择 Excel 中的列

转载 作者:行者123 更新时间:2023-12-02 21:24:28 25 4
gpt4 key购买 nike

Dim count As Integer
Dim myData As Workbook
Dim col As Integer, rng As Range, n#, b#

col = Selection.Column 'choose the column to count the values from

If Application.WorksheetFunction.CountA(Columns(col)) = 0 Then
MsgBox "You have selected a blank column"
n = 0
Else
Set rng = Intersect(Columns(col), ActiveSheet.UsedRange)
On Error Resume Next
b = rng.Cells.SpecialCells(xlCellTypeBlanks).count
n = rng.Cells.count - b - 1
On Error GoTo 0
Worksheets("sheet1").Select

我需要能够通过指定列号或名称来选择列,而不是 column.selection

最佳答案

只需使用 Columns(1) = 第一列Columns("A") = 第一列

Worksheet.Columns Property (Excel)

Returns a Range object that represents all the columns on the active worksheet. If the active document isn't a worksheet, the Columns property fails.

示例

Worksheets("Sheet1").Columns(1).Font.Bold = True

或者

WorksheetFunction.CountA(Columns(1))

WorksheetFunction.CountA(Columns(1)), same as column 1

关于vba - 我需要能够通过在 vba 中指定列号来选择 Excel 中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43840668/

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