【问题标题】:Highlight/select last entire row of macro突出显示/选择最后一整行宏
【发布时间】:2013-09-10 21:00:50
【问题描述】:

我有以下代码,我想确保复制一行 n 次后的最后一行突出显示/选择第 n 行。

示例:我复制了 11 行我想突出显示/选择第 11 行而不是复制的整个范围

Sub test2()
Dim n As Integer, rng As Range

    'new section >>
    On Error GoTo EH
    Set rng = Application.InputBox("Select any cell/cells within range to copy", Type:=8)
    '<<---

rng.Select

line2:
n = InputBox("type no. of times you want to be repeated minus 1 for e.g if you wnat to be repeated 3 times type 2")
Range(rng.Offset(1, 0), rng.Offset(n, 0)).EntireRow.Insert
Range(rng, rng.End(xlToRight)).Copy
Range(rng, rng.Offset(n, 0)).PasteSpecial

    'this section is not necessary>>
    'Set rng = rng.Offset(n + 1, 0)
    'If rng = "" Then
    'GoTo line1
    'Else
    'GoTo line2
    'End If

line1:
Application.CutCopyMode = False
    'range("a1").Select 'i don't think you need it
MsgBox "macro over"

    'Stop is not neede

Exit Sub
EH:
    MsgBox "Sub interrupted"

End Sub

谢谢

【问题讨论】:

  • 查看here以查找最后一行。

标签: excel selection rows highlight vba


【解决方案1】:

添加了一条消息和一条选择最后复制的单元格的行

rng.Offset(n, 0).Select
MsgBox "selected the last row" & rng.Offset(n, 0).Address

试试下面的

Sub test2()

    Dim n As Integer, rng As Range

    On Error GoTo EH
    Set rng = Application.InputBox("Select any cell/cells within range to copy", Type:=8)

    rng.Activate

line2:
    n = InputBox("type no. of times you want to be repeated minus 1 for e.g if you wnat to be repeated 3 times type 2")
    Range(rng.Offset(1, 0), rng.Offset(n, 0)).EntireRow.Insert
    Range(rng, rng.End(xlToRight)).Copy
    Range(rng, rng.Offset(n, 0)).PasteSpecial

    rng.Offset(n, 0).Select
    MsgBox "selected the last row" & rng.Offset(n, 0).Address

line1:
    Application.CutCopyMode = False

Exit Sub
EH:
    MsgBox "Sub interrupted"

End Sub

【讨论】:

    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 2016-03-27
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多