隐藏列:设置范围

Hiding Columns: setting the Range

提问人:JR Stroik 提问时间:10/16/2023 最后编辑:JR Stroik 更新时间:10/16/2023 访问量:45

问:

我的目的是将一个 ws 的一部分复制到另一个 ws 以进行格式化和打印。

在隐藏不必要的列时,我遇到了麻烦。下面的代码返回

编译错误:参数数错误或属性赋值无效--------已解决

运行时错误:1004 对象“_Worksheet”的方法“范围”失败

'shTarget.Range(“Rngc”)='应用程序定义或对象定义错误'

Private Sub IWasRunning()

Dim wbSource As Workbook
Dim wbTarget As Workbook
Dim shSource As Worksheet
Dim shTarget As Worksheet
Dim shHelper As Worksheet
Dim Rnga As Range
Dim Rngb As Range
Dim Rngc As Range

Set wbSource = Workbooks.Open(Filename:="E:\DE Daily Production Plan\A. Production Plans\(B. 1 of 2) Current Production Plans\Blue Line Schedule.XLSX", ReadOnly:=True)
Set wbTarget = Workbooks.Open(Filename:="E:\DE Daily Production Plan\A. Production Plans\(B. 1 of 2) Current Production Plans\Schedule Assist.XLSM", ReadOnly:=True)
Set shSource = wbSource.Worksheets("Schedule")
Set shTarget = wbTarget.Worksheets("DailyPrintable")
Set shHelper = wbTarget.Worksheets("Start")
Set Rnga = shHelper.Range("A1")
Set Rngb = shHelper.Range("B1")
                     
Set Rngc = shTarget.Range("A:B", "F:F", "H:L", "N:AD")

wbTarget.Names.Add Name:="SKE", RefersTo:=Rnga
wbTarget.Names.Add Name:="Daily", RefersTo:=Rngb

Application.ScreenUpdating = False

Stations = Array("3", "8", "13", "18", "23", "28")
For i = 0 To UBound(Stations)
   
   With shTarget.Rows(Stations(i))
     shSource.Rows(Range("SKE") + 2 - i).Rows("1:" & Range("Daily")).Copy
      shTarget.Rows(Range("Daily") * i + ("3" + i)).PasteSpecial Paste:=xlPasteAllUsingSourceTheme
End With
Next i

Application.CutCopyMode = False

With shTarget.Rows(2).Rows("1:" & Range("Daily") * 8).Font
        .Name = "Calibri"
        .Size = 24
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With
With shTarget.Rows(2).Rows("1:" & Range("Daily") * 8).Columns.AutoFit
    shTarget.Columns(4).Columns.ColumnWidth = 25
    shTarget.Rows(2).Rows("1:" & Range("Daily") * 8).RowHeight = 25
    End With
                'error occurs below 
    With shTarget.Range("Rngc")      'shTarget.Range("Rngc")=<application defined or object defined error>
         .EntireColumn.Hidden = True
    End With
         Application.ScreenUpdating = True
End Sub
Excel VBA 参数 范围 运行时错误

评论

0赞 CDP1802 10/16/2023
shTarget.Range("A:B, F:F, H:L, N:AD")
0赞 JR Stroik 10/16/2023
好了,我们开始吧:对象“_Worksheet”的方法“范围”失败
0赞 CDP1802 10/16/2023
Rngc是一个范围,所以不是With RngcWith shTarget.Range("Rngc")
0赞 JR Stroik 10/16/2023
棒!感谢您最初没有脱口而出这个和下一期的“with”块!
0赞 CDP1802 10/16/2023
shHelper.Range(“A1”) 和 shHelper.Range(“B1”) 中的典型值是什么

答: 暂无答案