Caveman1964
Board Regular
- Joined
- Dec 14, 2017
- Messages
- 127
- Office Version
- 2016
- Platform
- Windows
Hi, I have a code to find a job number and then enter a date. But if the data already exists, I don't want them to be able to put anything in there. Can one of you gurus add that in this code?
thanks ahead of time
Sub Enterdatecomplaintreceived()
Dim CrrntSht As String
CrrntSht = ActiveSheet.Name
Dim JobNumber As String
Dim JobRow As Integer
Dim LastCol As Integer
Dim NewDate As String
Application.ScreenUpdating = False
Sheets("Data Collection").Activate
'Find the job number in A:A in Data Collection
JobNumber = InputBox("Please enter a job number", "Job Number")
If Trim(JobNumber) <> "" Then
With Sheets("Data Collection").Range("A:A")
Set Rng = .find(What:=JobNumber, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
'job number found, find the last date in the row
Rng.Select
JobRow = ActiveCell.Row
LastCol = Cells(JobRow, Columns.Count).End(xlToLeft).Column
'ask for new date
NewDate = InputBox("Please enter the date", "Date")
'place the date
Cells(JobRow, 14).Value = NewDate
Else
MsgBox "Job number not found", vbExclamation, "Not found"
Sheets(CrrntSht).Activate
End If
End With
End If
Range("A1").Select
Sheets(CrrntSht).Activate
Application.ScreenUpdating = True
End Sub
thanks ahead of time
Sub Enterdatecomplaintreceived()
Dim CrrntSht As String
CrrntSht = ActiveSheet.Name
Dim JobNumber As String
Dim JobRow As Integer
Dim LastCol As Integer
Dim NewDate As String
Application.ScreenUpdating = False
Sheets("Data Collection").Activate
'Find the job number in A:A in Data Collection
JobNumber = InputBox("Please enter a job number", "Job Number")
If Trim(JobNumber) <> "" Then
With Sheets("Data Collection").Range("A:A")
Set Rng = .find(What:=JobNumber, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
'job number found, find the last date in the row
Rng.Select
JobRow = ActiveCell.Row
LastCol = Cells(JobRow, Columns.Count).End(xlToLeft).Column
'ask for new date
NewDate = InputBox("Please enter the date", "Date")
'place the date
Cells(JobRow, 14).Value = NewDate
Else
MsgBox "Job number not found", vbExclamation, "Not found"
Sheets(CrrntSht).Activate
End If
End With
End If
Range("A1").Select
Sheets(CrrntSht).Activate
Application.ScreenUpdating = True
End Sub