关于vba编程插入列

关于vba编程插入列,第1张

把下面的代码复制到你的程序中吧,加了'号释掉的这些都是被接下的一行代码取代了,我这边试了OK的,你的意思是每次点按钮,就在最后面加上两列,并设置只能输入大于2014.1.1这个日期的值.

Sub charu()

'Columns("AX:AY").Select

    'Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

    'Range("AX3").Select

 col1 = Range("iv3").End(xlToLeft).Column

 Cells(3, col1 + 1).Select

 

     With Selection.Interior

        .Pattern = xlSolid

        .PatternColorIndex = xlAutomatic

        .Color = 65535

        .TintAndShade = 0

        .PatternTintAndShade = 0

    End With

    ActiveCell.FormulaR1C1 = "再次消费日期"

    

    'Range("AY3").Select

    'ActiveCell.FormulaR1C1 = "再次消费金额"

    Cells(3, col1 + 2) = "再次消费金额"

    

    'Range("AX4:AX39").Select

    'Selection.NumberFormatLocal = "yyyy-m-d"

    Range(Cells(4, col1 + 1), Cells(39, col1 + 1)).NumberFormatLocal = "yyyy-m-d"

    

    'ActiveWindow.SmallScroll Down:=-36

    'Range("AY4:AY39").Select

    'ActiveWindow.SmallScroll Down:=-63

    'Range("AX4:AX39").Select

    'ActiveWindow.SmallScroll Down:=-48

     Range(Cells(4, col1 + 1), Cells(39, col1 + 1)).Select

     

    With Selection.Validation

        .Delete

        .Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _

        xlGreater, Formula1:="1/1/2014"

        .IgnoreBlank = True

        .InCellDropdown = True

        .InputTitle = ""

        .ErrorTitle = ""

        .InputMessage = ""

        .ErrorMessage = ""

        .IMEMode = xlIMEModeNoControl

        .ShowInput = True

        .ShowError = True

    End With

    'Range("AY4").Select

    Cells(4, col1 + 2).Select

End Sub

Columns("E:E").Select

    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

教你一个用VBA的技巧:

以后你想知道类似于插入的vba编码怎么写,可以利用宏录制,宏录制后会自动在编辑器中生成一个模块,你所录制的宏  的相应编码就在里面,这样你就可以参考使用了。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/7833939.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-10
下一篇2023-04-10

发表评论

登录后才能评论

评论列表(0条)

    保存