【问题标题】:Excel VBA. How to select a certain cell, then offset a variable number or rows down, and then print that selectionExcel VBA。如何选择某个单元格,然后向下偏移一个变量数或行,然后打印该选择
【发布时间】:2017-06-28 18:57:21
【问题描述】:

就像标题中所说的那样。我需要在从 B18 到 J18 的区域打印并向下打印可变数量的行。我不知道如何设置。通过使用=COUNTA(B20:B65536)函数将该变量编号保存在单元格O24 中。我只需要选择向下那么多行。

到目前为止,这是我的代码。

Sub PrintPlease()

I = Cells("O24").Value

With ActiveSheet.PageSetup
    .Zoom = False
    .Orientation = xlPortrait
    .FitToPagesWide = 1
    .FitToPagesTall = 1

    ExecuteExcel4Macro ("PAGE.SETUP(,,,,,,,,,,,,{#N/A,#N/A})")
    If .Zoom < 30 Then
        .Zoom = 50
    Else
        .Zoom = False
        .FitToPagesWide = 1
    End If

End With

Range ("B18:J18"), Cells("B18").Offset((I), 3).PrintOut, Preview:=True

End Sub

【问题讨论】:

  • Range("B18:J" &amp; Range("O24").Value).PrintOut Preview:=TrueRange("O24").Value 将返回单元格 O24 的值,然后将其附加到范围的其余部分,从 B18 开始
  • 行得通!将其放在答案部分并标记为正确。

标签: vba excel variables offset


【解决方案1】:

你可以使用

Range("B18:J" & Range("O24").Value).PrintOut Preview:=True

由于单元格 O24 中的值包含您要打印的行数,您可以通过将单元格 O24 中的值附加到 B18 来打印从单元格 B18 开始到单元格 J 结束的范围以及单元格 O24 的值: J.

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 2015-10-15
    • 2017-05-01
    • 2022-01-17
    • 1970-01-01
    • 2016-09-18
    • 2014-12-25
    • 1970-01-01
    • 2021-04-08
    相关资源
    最近更新 更多