宏删除所有数据

时间:2018-06-19 16:31:25

标签: excel vba excel-vba

我当前正在使用Excel 2016,并且试图创建一个宏来自动执行报表的每月格式化程序。出于某种原因,当我执行宏时,它会删除每一列,使我留下空白。

我查看了其他帖子,但找不到与我的问题类似的内容。因此,我在这里发布。

这是我需要宏执行的操作:

  1. 将单元格B3到B5之间的所有文本粘贴并粘贴到单元格A3到A5
  2. 删除整个B列
  3. 从B列选择到M列,并使其宽度为8英寸
  4. 转到“页面布局”标签(向右斜向下的小箭头):

    • 选择风景选项
      • 适合1乘6的人
    • 转到“保证金”选项卡
      • 修改左,右,下边距= 0.25上边距= 0.4
    • 转到工作表标签
      • 行从1重复到10

这是我完成宏后生成的原始代码:

Range("B3:B5").Select
Application.CutCopyMode = False
Selection.Cut
Range("A3").Select
ActiveSheet.Paste
Range("B:B").Select
Selection.Delete Shift:=xlToLeft
Columns("B:O").Select
Selection.ColumnWidth = 8
Application.PrintCommunication = False
With ActiveSheet.PageSetup
    .PrintTitleRows = "$1:$10"
    .PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
    .LeftHeader = ""
    .CenterHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints(0.25)
    .BottomMargin = Application.InchesToPoints(0.25)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .FooterMargin = Application.InchesToPoints(0.3)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 600
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlLandscape
    .Draft = False
    .PaperSize = xlPaperLetter
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 6
    .PrintErrors = xlPrintErrorsDisplayed
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .ScaleWithDocHeaderFooter = True
    .AlignMarginsHeaderFooter = True
    .EvenPage.LeftHeader.Text = ""
    .EvenPage.CenterHeader.Text = ""
    .EvenPage.RightHeader.Text = ""
    .EvenPage.LeftFooter.Text = ""
    .EvenPage.CenterFooter.Text = ""
    .EvenPage.RightFooter.Text = ""
    .FirstPage.LeftHeader.Text = ""
    .FirstPage.CenterHeader.Text = ""
    .FirstPage.RightHeader.Text = ""
    .FirstPage.LeftFooter.Text = ""
    .FirstPage.CenterFooter.Text = ""
    .FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
End Sub

0 个答案:

没有答案