excel - 如何在特定范围内插入单元格值?
问题描述
我一直在尝试从单元格中复制特定值,然后插入一个新列,其中所有记录都必须具有我在开头复制的值,(该值是文件中的日期)
我可以插入新列,其所有记录中复制的值,
问题是我需要从动态的特定范围复制所有行中的单元格值,但是使用我的实际代码我填写了所有行,直到最后一个 excel 行,而不仅仅是特定范围
细节
inicio = 范围变量的开始 fin = 范围变量的结束
我的代码是
Dim inicio As String
Dim fin As String
Cells.Find(What:="TOTAL GENERAL").Select
Selection.End(xlDown).Select
inicio = ActiveCell.row
Selection.End(xlDown).Select
fin = ActiveCell.row
Range("A1").Select
Selection.End(xlToRight).Select
Selection.Copy
我试图在 mi 代码中使用类似的东西,但它没有用
ActiveCell.EntireColumn.Insert.Range(ActiveCell, fin - 1).EntireColumn.Insert
我希望你能帮助我,非常感谢
解决方案
这是我的代码:
Sub NewColumn()
'Declarations.
Dim RngInicio As Range
Dim RngFin As Range
Dim DatDate As Date
'Setting variables.
Set RngInicio = Cells.Find(What:="TOTAL GENERAL").End(xlDown)
Set RngFin = RngInicio.End(xlDown)
DatDate = Range("A1").End(xlToRight).Value
'Inserting column.
RngInicio.EntireColumn.Insert
'Filling desired cells of the new column.
Range(RngInicio, RngFin).Offset(0, -1).Value = DatDate
End Sub
告诉我它是否适合您,如果您需要任何其他解释或改进。顺便说一句:尽量避免在代码中选择您需要的范围(或对象)。;)
推荐阅读
- flutter - Flutter 未处理异常:DioError [DioErrorType.other]
- airflow - 如何允许用户在 UI 中查看和运行单个 DAG
- node.js - Nestjs中同一模块中的多个服务
- apache-kafka - 未授权访问主题 - 使用 Kerberos SASL 协议实现的 Kafka 中的聚合存储错误
- ios - 广播视图 (MTHKView) 未扩展全屏
- python - 如何列出 /tmp 文件夹中的文件
- flutter - 如何在容器中显示国家代码
- python - MLKNN - __int__() 采用 1 个位置参数,但使用 fit 方法给出了 2 个
- python - 如何从嵌套字典中的值中删除特殊字符
- angular - 传单使功能同步