명명 된 베이가있는웨어 하우스를 나타내는 데이터베이스를 만들려고합니다. 이 기능에는 로그인 자료와 필요할 때 언제든지 확인할 수있는 기능이 있습니다.Excel VBA - 셀이 비어있는 경우 입력, 그렇지 않으면 반환 오류
My excel 통합 문서에는 로그인 시트가 있으며 행 A에서 행 G까지 레이블이 지정된 7 개의 시트가웨어 하우스의 통로를 나타냅니다. 각 통로에는 5 개의 선반과 여러 개의 베이가 있습니다. 이 정보는 연결되어 고유 한 위치를 제공합니다. 현재 VBA에 소재를 할당 할 위치가 비어 있는지 여부를 확인하는 데 어려움을 겪고 있습니다. 그렇다면 Log In 시트에서 복사 한 정보를 붙여 넣어야합니다. 불행히도, 내 시트에 무엇이든 상관없이 코드는 ActiveCell을 "TRUE"로 채우고 그것이 사실이 아닌 경우 요청한 오류 메시지를 표시합니다. 같은 결과로 IfEmpty도 시도했습니다.
내 코드는 다음과 같습니다 : 당신이 잘못 Selection
를 사용하는
Sub LogIn()
Dim Row As String
Dim Location As String
' assign values to variables
Worksheets("Log In").Activate
Location = Cells(6, 3).Value
Row = Cells(3, 3).Value
' copy new inputs to clipboard
Sheets("Log In").Range("C8:C11").Copy
' find the correct location within the separate racking sheets
Sheets("Row " & Row).Activate
Selection = Cells.Find(What:=Location, After:=Cells(1, 1), LookIn:=xlFormulas, _
lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, _
MatchCase:=False, searchformat:=False).Activate
Selection = Sheets("Log In").Cells(6, 3).Value
Selection = ActiveCell.Offset(0, 2).Activate
' check whether location is empty
If ActiveCell.Value = "" Then
' paste new inputs onto racking sheet
ActiveCell.PasteSpecial
' or return an error
Else: MsgBox "The location you have selected is currently occupied"
End If
End Sub
정말 잘 알고 있습니다. 시간을 절약하고 재기록하기 위해 필자는'ActiveCell.Offset'의 앞에서'Selection ='을 제거함으로써 간단하게 작동 시켰습니다. –