各位大神好,問一個小白的問題。因為作業需要自己做了一個小小的宏,不知道為什么帶有“插入列”這個命令的宏,執行之后,匯入的表格中只剩有我插入的3列資料,其他單元格都變成了空白。我需要的是在指定位置后插入3列,并分別輸入公式以便統計數量。附件是我做的宏和一個表格檔案,有沒有大神幫忙查看一下是什么問題。
需要的效果

執行之后的

宏:
Sub 宏1()
'
' 宏1 宏
'
'
Cells.Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Columns("R:R").Select
Range("R2").Activate
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("R3").Select
ActiveCell.FormulaR1C1 = "SDT"
Range("S3").Select
ActiveCell.FormulaR1C1 = "BTT"
Range("T3").Select
ActiveCell.FormulaR1C1 = "HHT"
Range("R3:R4").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Range("S3:S4").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Range("T3:T4").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
Range("R5").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-3]<24.77,IF(RC[-1]="""","""",RC[-1]),"""")"
Range("R5").Select
Selection.AutoFill Destination:=Range("R5:R99")
Range("R5:R99").Select
Range("S5").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-4]>=24.77,RC[-4]<63.15),IF(RC[-2]="""","""",RC[-2]),"""")"
Range("S5").Select
Selection.AutoFill Destination:=Range("S5:S99")
Range("S5:S99").Select
Range("T5").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-5]>=63.154,IF(RC[-3]="""","""",RC[-3]),"""")"
Range("T5").Select
Selection.AutoFill Destination:=Range("T5:T99")
Range("T5:T99").Select
Columns("R:T").Select
Range("R2").Activate
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With
End Sub
uj5u.com熱心網友回復:
單步執行,看是在哪一行出現不符合你預期的結果了uj5u.com熱心網友回復:
注釋掉所有On Error Resume Next陳述句,在VBA IDE中運行,出錯后點擊除錯,游標會停在出錯的那條陳述句處,
或者
事先在懷疑可能有邏輯錯誤的陳述句處設定斷點,運行經過斷點時中斷,
此時可以在立即視窗中使用
?變數名
或
?函式名(函式引數)
或
程序名(引數)
輔助除錯。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/51379.html
標籤:VB基礎類
