简体   繁体   English

当我运行宏时,它会将字段中的数据清空

[英]When I run a macro it blanks the data in the fields

Why are all fields blank after this macro is executed?为什么执行此宏后所有字段都为空? When I run this macro it blanks all of the data in the fields but formats the sheet correctly.当我运行这个宏时,它会清空字段中的所有数据,但会正确格式化工作表。 It happens between the.apply and End with, just before the active window screens.它发生在.apply 和 End with 之间,就在活动的 window 屏幕之前。 I did not write this macro, any help would be appreciated.我没有写这个宏,任何帮助将不胜感激。

I have used the step into feature to find where this unwanted behavior happens.我已经使用 step into 功能来查找这种不需要的行为发生的位置。

    Columns("T:AD").Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("I:S").Select
    Range("S1").Activate
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    Range("A1:S1000").Select
    Range("D1").Activate
    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
    Columns("G:G").EntireColumn.AutoFit
    Columns("I:I").EntireColumn.AutoFit
    Cells.Select
    Range("D1").Activate
    Cells.EntireColumn.AutoFit
    Rows("1:1").Select
    Range("D1").Activate
    Selection.Font.Bold = True
    Cells.Select
    Range("D1").Activate
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("P2:P1000") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A1:AD1000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveWindow.SmallScroll Down:=-33
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 7
    ActiveWindow.ScrollColumn = 8
    ActiveWindow.ScrollColumn = 9
    ActiveWindow.ScrollColumn = 10
    ActiveWindow.ScrollColumn = 11
    ActiveWindow.ScrollColumn = 12
    ActiveWindow.ScrollColumn = 13
    ActiveWindow.ScrollColumn = 14
    ActiveWindow.ScrollColumn = 15
    ActiveWindow.ScrollColumn = 16
    Range("A28").Select
    ActiveWindow.SmallScroll Down:=-75
    Rows("2:2").Select
    Selection.Delete Shift:=xlUp
End Sub

Why are you doing this:你为什么做这个:

Columns("I:S").Select

You are selecting all columns entirely, and then afterwards (as correctly mentioned by Tin Bum) you are deleting everything left of those columns.您正在完全选择所有列,然后(正如 Tin Bum 正确提到的那样)您将删除这些列剩下的所有内容。

At the end, you're also deleting the first two rows entirely, but I believe that's not a big problem.最后,您还完全删除了前两行,但我相信这不是一个大问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM