excel - 有没有可以修复我当前代码的代码?
问题描述
我创建了一个签入/签出系统。我的代码仅适用于一张纸时效果很好。但是当我尝试将此代码应用于多个工作表时,出现错误,我尝试了三个代码,但仍然无法让 excel 将代码应用于每个单独的工作表。我使用的任何代码都会混淆 excel 并将我重定向到第一张表。
我使用的第一个代码
dim WS as worksheet
for each WS in sheets
(my code)
next WS
我使用的第二个代码
For Each Worksheet In ThisWorkbook.worksheets
sheets("may","June","july").activate
(my code)
next worksheet
我也试过了,(worksheet.activate)但是这段代码将我重定向到第一张表并丢失其他表上的数据
这是我正在尝试开始工作的当前代码
Sub Check_in()
For Each Worksheet In ThisWorkbook.worksheets
worksheets("April", "May", "June").Activate
Dim code As String: code = InputBox("Please scan a barcode", "Scan procedure")
If code = "" Then MsgBox ("No code scanned"): Exit Sub
Dim NbChIn As Integer: NbChIn = application.CountIf(Range("STORE_RECORDS [CHECKED OUT on its way to analytical lab]"), code)
Dim NbChOut As Integer: NbChOut = application.CountIf(Range("STORE_RECORDS[SAMPLE RECEIVED from analytical lab]"), code)
If NbChIn > NbChOut And NbChIn > 0 Then
MsgBox ("This sample is already Checked-out" & Chr(10) & "Please click sample received and retry"): Exit Sub
Else
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = code
Cells(Rows.Count, 1).End(xlUp).Offset(0, 1) = Now
End If
Next Worksheet
End Sub
Sub Check_Out()
Dim code As String: code = InputBox("Please scan a barcode", "Scan procedure")
If code = "" Then MsgBox ("No code scanned"): Exit Sub
Dim NbChIn As Integer: NbChIn = application.CountIf(Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]"), code)
Dim NbChOut As Integer: NbChOut = application.CountIf(Range("STORE_RECORDS[SAMPLE RECEIVED from analytical lab]"), code)
If NbChIn = NbChOut And NbChIn > 0 Then
MsgBox ("This sample has already been received" & Chr(10) & "Please check it out and retry"): Exit Sub
Else
If Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]").Find(code, , , xlWhole, , xlPrevious) Is Nothing Then MsgBox ("No match, ask Carlos !"): Exit Sub
Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]").Find(code, , , xlWhole, , xlPrevious).Offset(0, 2) = code
Range("STORE_RECORDS[CHECKED OUT on its way to analytical lab]").Find(code, , , xlWhole, , xlPrevious).Offset(0, 3) = Now
End If
End Sub'
代码通常会显示错误数量的参数,或者对象不支持此属性或方法。代码仅适用于工作表 1 或在我的情况下(四月)我希望此代码适用于按月组织的每张工作表。
解决方案
推荐阅读
- java - 升级先前初始化的 Karaf 实例的 JDK 后,Felix 文件安装停止工作
- json - 如何在下拉列表中显示 JSON 数据?
- python - Return 语句在 python 3 中不起作用,它不返回任何内容,尝试使用 yield 但仍然相同
- appgyver - AppGyver QR Reading - 如何使用 QR 码读取 JSON 数据?
- collections - 在页面模板 Shopify 中复制 collection.products 数组
- stored-procedures - 从存储过程调用包 - Db2 z/OS
- python - 使用对象作为文件路径从 exe 文件中提取多个图标
- sql - 排名函数和连接
- python - 权限被拒绝:'/usr/lib/python3.7/multiprocessing/semaphore_tracker.py'
- random - $urandom 不生成任何数字