excel - else if statement for check in check out sheet vba not working
问题描述
I have an excel sheet in which lies a data entry form and a check in check out list. I have a macro set up to search for the entry, and if it doesnt exist, make a new entry with a checkout time, if it does exist, it checks it back in with a time. My issue lies when I try to check out an entry that already exists. The code just updates the check in time. Ive added an elseif statement into the code but it doesnt seem to do anything. If anyone could help me figure out why itd be much appreciated.
Sub inout()
Dim barcode As String
Dim rng As Range
Dim rownumber As Long
barcode = Worksheets("Sheet1").Cells(2, 2)
Set rng = Sheet1.Columns("a:a").Find(What:=barcode, _
LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If rng = True Or ActiveCell.Offset(0, 2).Value = True Then
rownumber = rng.Row
Worksheets("Sheet1").Cells(rownumber, 1).Select
ActiveCell.Offset(0, 2).Clear
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Date & " " & Time
ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"
Worksheets("Sheet1").Cells(2, 2) = ""
Cells(2, 2).Select
ElseIf rng Is Nothing Then
ActiveSheet.Columns("a:a").Find("").Select
ActiveCell.Value = barcode
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Date & " " & Time
ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"
Worksheets("Sheet1").Cells(2, 2) = ""
ActiveCell.Offset(0, 3).Select
ElseIf rng = True Then
rownumber = rng.Row
Worksheets("Sheet1").Cells(rownumber, 1).Select
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = Date & " " & Time
ActiveCell.NumberFormat = "m/d/yyyy h:mm AM/PM"
Worksheets("Sheet1").Cells(2, 2) = ""
rng.Offset(, 1).Clear
ActiveCell.Offset(0, 2).Value = "TOOL CRIB"
Cells(2, 2).Select
End If
End Sub
解决方案
推荐阅读
- javascript - Puppeteer 更改已打开浏览器页面的代理
- python - 从 Slic3r gcode 中提取坐标到文本 x,y,z,e,f
- javascript - 如何锁定我的机器人不被其他公会使用?
- android - 尾随点文本动画
- java - 列表模式的长度
- c++ - 使用 boost 或标准库扩展 Windows 环境变量
- reactjs - Facebook 登录函数在 ReactJS 应用程序中返回未定义
- c++ - 编译找不到非虚函数
- c# - ASP.NET Web API 响应在浏览器和 Postman 中显示转义字符
- javascript - 尽管我添加了空数组,但 React 限制了渲染的数量以防止无限循环