vba - 从特定行开始选择多列
问题描述
我的问题与这个问题非常相似,但我仍然不知道自己该怎么做。我想做和这里一样的事情:Excel VBA - 不按顺序选择多个列,除了我不需要整列,而是从特定行号开始的整列。
因此,就我而言,我希望在范围内有多个列,从第 30 行开始到每个选定列的末尾。但不是工作表上的所有列,只有少数。
解决方案
您绝对可以使用宏录制来模拟您想要选择的第一列的内容,然后根据您的需要进行修改
这是示例代码,它将使用预定义的常量执行您想要的操作
修改列列表和起始行的常量
Sub CustomColumnSelection()
' Describe what columns you want to select
Const ColumnList As String = "A,C,D"
' Row to start at
Const StartAtRow As Long = 5
Dim lngLastRow As Long
Dim arrColumns As Variant
Dim strSelect As String
Dim i As Integer
' Create an array to hold columns
arrColumns = Split(ColumnList, ",")
' Calculate last row of data in column
With ActiveSheet
lngLastRow = .Cells(.Rows.Count, arrColumns(0)).End(xlUp).Row
End With
' Define first column to select
strSelect = arrColumns(0) & StartAtRow
' and add rows to last ne found above
strSelect = strSelect & ":" & arrColumns(0) & lngLastRow
' Add rest of columns to selection list
For i = 1 To UBound(arrColumns)
strSelect = strSelect & "," & arrColumns(i) & StartAtRow & ":" & arrColumns(i) & lngLastRow
Next i
Range(strSelect).Select
End Sub
这是具有用于选择特殊单元格的良好示例 excel-vba 代码的众多站点之一
推荐阅读
- unity3d - How do I serialize ScriptableObjects?
- python - 具有大量数据的平滑 matplotlib 图(PyQt5)
- android - 如何在 Pie Slice 中垂直绘制文本?
- ios - CoreML 是设备本地的(iOS)吗?
- css - 删除选择 CSS 上的黑色方块
- r - R - 无法在 Mac 上安装 swirl
- python-3.x - pip3:需要属性'Cryptography_HAS_SSL_ST'
- linux - 使用 iptables,如何限制 IP 范围和浏览器字符串的连接?
- android - 使用 androidstudio 创建新的 NDK 项目时出现 Cmake 错误
- node.js - 无法停止使用 pm2 进程管理器启动的 node.js 应用程序