0

我需要合并 2 个宏,我尝试了相同的方法,但第一个宏的结尾显示错误。请在这方面提供帮助,

Sub ERS()
'
' ERS Macro
'

'
    ActiveWindow.SmallScroll Down:=-6
    Range("E1:E41").Select
    Selection.End(xlUp).Select
    Range("E2:E100").Select
    Selection.TextToColumns Destination:=Range("E2"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :=".", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
        1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1)), _
        TrailingMinusNumbers:=True
    Range("P2").Select
    ActiveCell.FormulaR1C1 = "=RC[-5]&RC[-4]"
    Range("P2").Select
    Selection.Copy
    Application.CutCopyMode = False
    Selection.AutoFill Destination:=Range("P2:P100"), Type:=xlFillDefault
    Range("P2:P100").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveWindow.SmallScroll Down:=-21
    Selection.Replace What:="\", Replacement:=".", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    ActiveWindow.SmallScroll Down:=-3


    Windows("qty.xls").Activate
    ActiveWindow.SmallScroll Down:=-12
    Range("M2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-9],lots.xlsx!R2C2:R100C16,15,0)"
    Range("M2").Select
    Selection.Copy
    Range("N2").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=RC[-1]*RC[-6]"
    Range("M2:N2").Select
    Selection.Copy
    Range("M2:N100").Select
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=-12
End Sub
4

1 回答 1

0

试试这个代码(未测试

如果您有任何错误,请告诉我。还要提到错误消息和给你错误的行

Sub ERS()
    Dim lRow As Long

    With Thisworkbook.ActiveSheet
        lRow = .Range("E" & .Rows.Count).End(xlUp).Row

        .Range("E2:E" & lRow).TextToColumns Destination:=.Range("E2"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :=".", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
        1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1)), _
        TrailingMinusNumbers:=True

        With .Range("P2:P" & lRow)
            .FormulaR1C1 = "=RC[-5]&RC[-4]"
            .Value = .Value

            .Replace What:="\", Replacement:=".", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        End With
    End With

    Windows("qty.xls").Activate
    Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-9],lots.xlsx!R2C2:R100C16,15,0)"
    Range("N2").FormulaR1C1 = "=RC[-1]*RC[-6]"
    Range("M2:N2").Copy Range("M2:N100")
End Sub

我还建议您阅读内容。这正是您应该避免使用的原因.Select

于 2012-08-17T08:53:22.447 回答