基本上我正在做一张工作表,它将有一个按钮来添加一个需要格式化的新行。不过我需要在工作表中的两个可选位置添加行。第一行我可以做到这一点。第二个我遇到麻烦,因为我需要动态设置它以识别位置在其他行被添加到顶部之后的位置。
例如:
John Oliver Old
Charlie Brown Young
Louis Vouitton Child
一个按钮就是在John Oliver Old(正在工作)之前添加一行 第二个按钮需要在Louis Vouitton之前添加一行
我的问题是我需要Macros知道“Lousi Vuitton”在哪一行中,以便知道在哪一行添加。
Sub AddSafetyRow()
'
' AddSafetyRow Macro
'
'
Rows("10:10").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
Range("A10:BV10").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection.Font
.Name = "Arial"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Selection.Font.Size = 10
Range("A10:C10").Select
Selection.Font.Bold = True
Range("B10").Select
Selection.Font.Size = 11
Selection.Font.Size = 12
Range("BO10").Select
ActiveCell.FormulaR1C1 = "Hector Vela"
Range("B10").Select
ActiveCell.FormulaR1C1 = "Safety Audit"
Range("A10").Select
ActiveCell.FormulaR1C1 = Format(Date, "mmmm")
Range("B10").Select
ActiveWindow.ScrollColumn = 4
End Sub
这就是我到目前为止所看到的,因为你可以看到一切都是硬编码的,以便遵循特定的位置,我需要将所有硬编码的值变为动态,以便为我的预期目的而工作。感谢您提供的任何帮助。