[英]How To Select Entire Column Except Header/First Row In Excel using VBA
我正在嘗試選擇第一行以外的整個列。 我使用了從https://www.extendoffice.com/documents/excel/1628-excel-select-column-except-header-first-row.html獲得的以下代碼
Sub SelectColumn()
Dim xColIndex As Integer
Dim xRowIndex As Integer
xColIndex = Application.ActiveCell.Column
xRowIndex = Application.ActiveSheet.Cells(Rows.Count, xColIndex).End(xlUp).Row
Range(Cells(2, xColIndex), Cells(xRowIndex, xColIndex)).Select
End Sub
但是RowIndex變量讀取的值為1。因此,該部分從Row2到Row1,而不是從Row2到最后一行。 我該如何糾正
如果您確實需要選擇整個列(為什么?),則此操作。 在您的示例中,相關列中沒有任何數據。
Range(Cells(2, xColIndex), Cells(rows.count, xColIndex)).Select
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.