如何解决将单元格文本和填充转换为 VBA 宏
我想知道有一种方法可以将单元格值和格式转换为宏。 在这个例子中,我只需要文本和单元格的填充。
我正在寻找一种方法来分析一系列单元格,然后转换为宏,某种宏记录器,但不是记录它,而是分析单元格并将其转换为宏。
如果我运行记录器,我会得到这个输出:
Sub Macro3()
Range("E1,F2,G3,H4,I5,J6,F1:J1,E2:E7,F3:F4,G2:I2").Select
Range("G2").Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("S1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("T1").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).Linestyle = xlNone
Selection.Borders(xlDiagonalUp).Linestyle = xlNone
Selection.Borders(xlEdgeLeft).Linestyle = xlNone
Selection.Borders(xlEdgetop).Linestyle = xlNone
Selection.Borders(xlEdgeBottom).Linestyle = xlNone
Selection.Borders(xlEdgeRight).Linestyle = xlNone
Selection.Borders(xlInsideVertical).Linestyle = xlNone
Selection.Borders(xlInsideHorizontal).Linestyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.Addindent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "Text here"
Range("E8,F5:F9,G4:G8,E9:E13,H3:M3,J2:N2,K1:P1,H5:H10").Select
Range("H5").Activate
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("S2").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("T2").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).Linestyle = xlNone
Selection.Borders(xlDiagonalUp).Linestyle = xlNone
Selection.Borders(xlEdgeLeft).Linestyle = xlNone
Selection.Borders(xlEdgetop).Linestyle = xlNone
Selection.Borders(xlEdgeBottom).Linestyle = xlNone
Selection.Borders(xlEdgeRight).Linestyle = xlNone
Selection.Borders(xlInsideVertical).Linestyle = xlNone
Selection.Borders(xlInsideHorizontal).Linestyle = xlNone
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.Addindent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.FormulaR1C1 = "Text here"
Range("T3").Select
End Sub
我希望创建完全相同的代码,但不是通过录制宏,而是通过从现有工作表中提取数据。
有人知道如何做到这一点吗?
亲切的问候
拉斐尔
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。