我需要能够通过在vba中指定列号来selectExcel中的列

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 ,我需要能够通过指定列号或名称来select列。

只需使用Columns(1) = Column oneColumns("A") = Column one

Worksheet.Columns属性(Excel)

返回表示活动工作表上所有列的Range对象。 如果活动文档不是工作表,则“列”属性将失败。

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

要么

WorksheetFunction.CountA(列(1))

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