gpt4 book ai didi

excel - VBA 400 错误 - 无法调试搜索/复制功能

转载 作者:行者123 更新时间:2023-12-04 22:10:07 24 4
gpt4 key购买 nike

我是新手/正在学习 VBA。对于这个问题,我在运行代码时没有得到调试按钮,所以我找不到错误。当我运行下面的宏时,错误只是说“400”,之后没有调试选项。

    Sub Search_and_Copy_Discount_and_Shopper()
Dim strStartingCell As String
Dim strCustomer As String
Dim strDiscount As String
Dim strShopper As String

'store starting place
'look at column A, store value
strStartingCell = ActiveCell.Address
strCustomer = ActiveCell.Offset(0, -1).Value

'go to customer sheet
Sheets("Customer").Select
Range("A2").Select

'compare values in A to strCustomer
'if it matches, copy cells 1 and 2 to the right in values
'if no match, go down one cell and check again
Do While IsEmpty(ActiveCell.Value) = False
If ActiveCell.Value = strCustomer Then
strDiscount = ActiveCell.Offset(0, 1).Value
strShopper = ActiveCell.Offset(0, 2).Value
Exit Sub
Else
ActiveCell.Offset(1, 0).Select
End If
Loop

'go back to purchases sheet
Sheets("Purchases").Select

'copy in current cell and cell 1 to the right
Range(strStartingCell).Select

'paste strDiscount in current cell
'paste strShopper in cell 1 to the right
ActiveCell.Value = strDiscount
ActiveCell.Offset(0, 1).Value = strShopper

End Sub

您可以识别的任何指针或错误将不胜感激!

最佳答案

您是否尝试过添加:

On Error GoTo error_handler

在第一行代码和:
Exit Sub

error_handler:
MsgBox Err.Description

就在“结束子”之前。

关于excel - VBA 400 错误 - 无法调试搜索/复制功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9206446/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com