如何合并这两个宏?(Excel 2010)

如何合并这两个宏?(Excel 2010)

我完全没有编程宏的经验(但我仍然可以录制宏,这对我有帮助)

所以,我想问如何将宏的这一部分“插入”到整个宏代码中?它们是整个宏:

    Sub CaseOpen1()
'
' CaseOpen1 Macro
'

'
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End Sub

而且,我想要“插入”的宏部分是:

    CaseOpen1 Macro
 Dim rng As Range
 Set rng = ActiveSheet.Range("G5")
 '  
 '
 '
 'With rng.Interior
 '

哦,如果你觉得代码有误,你可以随时改正。你一定比我做得更好。

感谢所有帮助。:)

答案1

像这样?

Sub Sample()
    Dim ws As Worksheet
    Dim rng As Range

    '~~> Change this to the relevant worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")
    Set rng = ws.Range("G5")

    With rng.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End Sub

相关内容