Excel单击附加宏的按钮时崩溃

时间:2015-09-09 15:54:38

标签: excel vba excel-vba

我有一个附加到按钮的宏。但是,当我在VBA编辑器中测试它时,它运行正常。当单击按钮并附加宏时,它会崩溃。我附加了其他宏,运行正常。

这是我的代码:

Option Explicit

Sub rma_new()

Dim Sno As Long, LRow As Long, NewRow As Long
Dim wsO As Worksheet, wsI As Worksheet
Dim customeRef, customerName, customerCountry
Dim customerCompany, datePaid, dateShipped
Dim webInvoiceNumber, invoiceNumber, postCode
Dim assignedTo, salesChnl, orderValue

Set wsO = ThisWorkbook.Sheets("RMA")
Set wsI = ThisWorkbook.Sheets("Sheet 1")

'~~> Get values from Sheet1
With wsI
    customeRef = .Range("c" & (ActiveCell.Row))
    customerName = .Range("d" & (ActiveCell.Row))
    customerCountry = .Range("e" & (ActiveCell.Row))
    customerCompany = .Range("f" & (ActiveCell.Row))
    datePaid = .Range("g" & (ActiveCell.Row))
    dateShipped = .Range("h" & (ActiveCell.Row))
    webInvoiceNumber = .Range("i" & (ActiveCell.Row))
    invoiceNumber = .Range("j" & (ActiveCell.Row))
    postCode = .Range("k" & (ActiveCell.Row))
    salesChnl = .Range("o" & (ActiveCell.Row))
    orderValue = .Range("a" & (ActiveCell.Row))


End With

'~~> Work with RMA Sheet
With wsO
    '~~> Get the last Row
    LRow = .Range("A" & .Rows.Count).End(xlUp).Row
    '~~> Increment the number
    Sno = .Range("A" & LRow).Value + 1
    '~~> New row where we need to write
    NewRow = LRow + 1

    .Cells(NewRow, 1) = Sno
    .Cells(NewRow, 2) = customeRef
    .Cells(NewRow, 3) = customerName
    .Cells(NewRow, 4) = customerCountry
    .Cells(NewRow, 5) = customerCompany
    .Cells(NewRow, 6) = datePaid
    .Cells(NewRow, 7) = dateShipped
    .Cells(NewRow, 8) = webInvoiceNumber
    .Cells(NewRow, 9) = invoiceNumber
    .Cells(NewRow, 10) = postCode
    .Cells(NewRow, 12) = salesChnl
    .Cells(NewRow, 14) = orderValue

End With

End Sub

0 个答案:

没有答案