求助EXCEL 插入列的宏命令无法执行

skyanjo_M 2017-11-09 03:54:26
各位大神好,问一个小白的问题。因为工作需要自己做了一个小小的宏,不知道为什么带有“插入列”这个命令的宏,执行之后,导入的表格中只剩有我插入的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

...全文
596 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
脆皮大雪糕 2017-11-15
  • 打赏
  • 举报
回复
单步执行,看是在哪一行出现不符合你预期的结果了
赵4老师 2017-11-15
  • 打赏
  • 举报
回复
注释掉所有On Error Resume Next语句,在VBA IDE中运行, 出错后点击调试,光标会停在出错的那条语句处, 或者 事先在怀疑可能有逻辑错误的语句处设置断点,运行经过断点时中断, 此时可以在立即窗口中使用 ?变量名 或 ?函数名(函数参数) 或 过程名(参数) 辅助调试。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧