select 单独工作表中除 header 列之外的所有行
select all rows for column except header in a seperate worksheet
我已经尝试了各种方法和答案 select 除了特定列的 header 之外的所有行和 none 似乎都有效。
我试过使用(15 是这里的列):
Range(Cells(2, 15), Cells(.Cells(rows.Count, 15).End(xlUp).Row, 15)).Select
我设法在工作sheet 上使用了 select 的不同语句,但这改变了 sheet,你可以明显地看到所有正在 select 编辑行。这对我需要它来说是不可能的。用户不能有一堆 sheet 不断地在他们面前切换,这会导致糟糕的体验。
如何在不使用 .Activate
的情况下 select header(第一)行之后的所有 non-blank 列?
我需要获取这些值,将它们放入数组中,并检查当前单元格值是否在数组中。不要求这部分,但如果重要的话将其作为上下文提供。
以下代码从工作表中读取数据(不使用 Select
或 Activate
),并将其放入二维数组中。
Option Explicit
Sub Range_WO_Headers()
Dim Sht_Source As Worksheet
Dim Rng As Range
Dim LastRow As Long
Dim LastCol As Long
Dim Rng_Array As Variant
' modify Sheet1 according to your sheet name
Set Sht_Source = ActiveWorkbook.Worksheets("Sheet1")
' assuming the table's data starts from Cell A1
LastRow = Sht_Source.Cells(Sht_Source.Rows.Count, "A").End(xlUp).Row
LastCol = Sht_Source.Cells(1, Sht_Source.Columns.Count).End(xlToLeft).Column
' resize array according to number of columns and number of rows
ReDim Rng_Array(0 To LastRow, 0 To LastCol)
' set dynamic array from Cell A1 to last row and last column found (starting the second row)
Set Rng = Sht_Source.Range(Cells(2, 1), Cells(LastRow, LastCol))
Rng_Array = Application.Transpose(Rng)
End Sub
您不能在 non-active 工作表上 select 范围。
这里介绍了如何设置对列中除 header 行以外的所有单元格的引用。
Dim TargetRange As Range
With Worksheets("Sheet1")
Set TargetRange = .Range(.Cells(2, 15), .Cells(Rows.Count, 15).End(xlUp))
End With
我已经尝试了各种方法和答案 select 除了特定列的 header 之外的所有行和 none 似乎都有效。
我试过使用(15 是这里的列):
Range(Cells(2, 15), Cells(.Cells(rows.Count, 15).End(xlUp).Row, 15)).Select
我设法在工作sheet 上使用了 select 的不同语句,但这改变了 sheet,你可以明显地看到所有正在 select 编辑行。这对我需要它来说是不可能的。用户不能有一堆 sheet 不断地在他们面前切换,这会导致糟糕的体验。
如何在不使用 .Activate
的情况下 select header(第一)行之后的所有 non-blank 列?
我需要获取这些值,将它们放入数组中,并检查当前单元格值是否在数组中。不要求这部分,但如果重要的话将其作为上下文提供。
以下代码从工作表中读取数据(不使用 Select
或 Activate
),并将其放入二维数组中。
Option Explicit
Sub Range_WO_Headers()
Dim Sht_Source As Worksheet
Dim Rng As Range
Dim LastRow As Long
Dim LastCol As Long
Dim Rng_Array As Variant
' modify Sheet1 according to your sheet name
Set Sht_Source = ActiveWorkbook.Worksheets("Sheet1")
' assuming the table's data starts from Cell A1
LastRow = Sht_Source.Cells(Sht_Source.Rows.Count, "A").End(xlUp).Row
LastCol = Sht_Source.Cells(1, Sht_Source.Columns.Count).End(xlToLeft).Column
' resize array according to number of columns and number of rows
ReDim Rng_Array(0 To LastRow, 0 To LastCol)
' set dynamic array from Cell A1 to last row and last column found (starting the second row)
Set Rng = Sht_Source.Range(Cells(2, 1), Cells(LastRow, LastCol))
Rng_Array = Application.Transpose(Rng)
End Sub
您不能在 non-active 工作表上 select 范围。
这里介绍了如何设置对列中除 header 行以外的所有单元格的引用。
Dim TargetRange As Range
With Worksheets("Sheet1")
Set TargetRange = .Range(.Cells(2, 15), .Cells(Rows.Count, 15).End(xlUp))
End With