任何人都可以帮我解决一个小问题吗?我有一个报告,当单击 VBA 按钮时创建一个表,并从其他两个表中选择 xlookup,但在此处的代码中
Selection.AutoFill Destination:=Range("I2:I300") Range("I2:I300").Select
我已将其设置为 300 行,但有时是 200,有时是 150 行,所有其余行在 hte 表中然后返回数字 0。你知道有人如何设置此代码吗ActiveCell.FormulaR1C1 = "=XLOOKUP(RC[-7],Route!C[-8],Route!C[14])"
,它将计数到 300,但如果我只有 200 行,则 I 列中的所有其余空行将保留为空白而不是数字 0 ?
`子报告
Sheets("report1").Select
Rows("1:5").Select
Selection.Delete Shift:=xlUp
Columns("A:B").Select
Selection.Delete Shift:=xlToLeft
Columns("F:K").Select
Selection.Delete Shift:=xlToLeft
Columns("I:Q").Select
Selection.Delete Shift:=xlToLeft
Columns("I:I").Select
Selection.ClearContents
Cells.Select
With Selection
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("I1").Select
ActiveCell.FormulaR1C1 = "Cases"
Range("I2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=XLOOKUP(RC[-7],Route!C[-8],Route!C[14])"
Selection.AutoFill Destination:=Range("I2:I300")
Range("I2:I300").Select
Range("A1:J1").Select
Range(Selection, Selection.End(xlDown)).Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
Selection.Font.Underline = xlUnderlineStyleSingle
Selection.Font.Underline = xlUnderlineStyleNone
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
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("A1").Select
Call SendEmail
结束子`
您需要添加 if_not_found 参数:
ActiveCell.FormulaR1C1 = "=XLOOKUP(RC[-7],Route!C[-8],Route!C[14],"""")"