![](/img/trans.png)
[英]How to select fixed part of rows based on cells selection , Excel vba?
[英]How to copy fixed part of rows based on cell selection , Excel vba?
我有很多列的表,如果我需要 select 單元格 B3 或 C3(例如)復制同一行上的單元格 B3:G3。
選擇可以是工作表上的任何行。 可以用 vba 完成嗎? 樣品表附在此鏈接上https://easyupload.io/8knzr9
B
and/or C
, it will select their rows, but in columns B:G
. 工作表模塊,例如Sheet1
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const cFirstRow As String = "B3:C3"
Const sCols As String = "B:G"
Dim crg As Range
With Range(cFirstRow)
Set crg = .Resize(Rows.Count - .Row + 1)
End With
Dim irg As Range: Set irg = Intersect(crg, Target)
If Not irg Is Nothing Then
Dim srg As Range, arg As Range, rrg As Range
For Each arg In irg.Areas
For Each rrg In arg.Rows
If srg Is Nothing Then
Set srg = Columns(sCols).Rows(rrg.Row)
Else
Set srg = Union(srg, Columns(sCols).Rows(rrg.Row))
End If
Next rrg
Next arg
If Not srg Is Nothing Then
srg.Select
End If
End If
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.