In Master Sheet there are three cells in attached sheet G1,G2 & J2. When I will run macro it should check that whether values are entered in these cells. If any one of cells are blank, cell should be RED and give message that values are not entered. and then it should ask Do you want to enter data now, if yes input box for entering value.
Option Explicit
Dim birth As Range, PANNo As Range, empName As Range, userInput
Sub validateData()
Application.ScreenUpdating = False
Set birth = [G2]
Set PANNo = [J2]
Set empName = [G1]
If IsEmpty(empName) Then
[empName].Interior.ColorIndex = 3
[empName].Interior.Pattern = xlSolid
If MsgBox("Employee Name is empty;Please enter now", vbYesNo) = vbYes Then
userInput = Application.InputBox("Please Enter Employee name", Type:=2)
If Len(userInput) > 0 Then
[empName].Value = userInput
[empName].Interior.ColorIndex = 2
End If
End If
End If
If IsEmpty(birth) Then
[birth].Interior.ColorIndex = 3
[birth].Interior.Pattern = xlSolid
If MsgBox("Date of Birth is empty; Please enter now", vbYesNo) = vbYes Then
userInput = vbNullString
userInput = Application.InputBox("Enter DOB", "DOB in mm/dd/yyyy format", Default:=Format(Date, "mm/dd/yyyy"), Type:=2)
If IsDate(userInput) Then
[birth].Value = userInput
[birth].Interior.ColorIndex = 2
End If
End If
End If
If IsEmpty(PANNo) Then
[PANNo].Interior.ColorIndex = 3
[PANNo].Interior.Pattern = xlSolid
If MsgBox("PAN No. is empty;Please enter now", vbYesNo) = vbYes Then
userInput = vbNullString
userInput = Application.InputBox("Enter PAN No.", "PAN No.", Type:=2)
If Len(userInput) = 10 Then
[PANNo].Value = userInput
[PANNo].Interior.ColorIndex = 2
End If
End If
End If
End Sub
https://docs.google.com/file/d/0B23eJ2xd9ODybDdROVo4dUxLVjA/edit?usp=sharing
Option Explicit
Dim birth As Range, PANNo As Range, empName As Range, userInput
Sub validateData()
Application.ScreenUpdating = False
Set birth = [G2]
Set PANNo = [J2]
Set empName = [G1]
If IsEmpty(empName) Then
[empName].Interior.ColorIndex = 3
[empName].Interior.Pattern = xlSolid
If MsgBox("Employee Name is empty;Please enter now", vbYesNo) = vbYes Then
userInput = Application.InputBox("Please Enter Employee name", Type:=2)
If Len(userInput) > 0 Then
[empName].Value = userInput
[empName].Interior.ColorIndex = 2
End If
End If
End If
If IsEmpty(birth) Then
[birth].Interior.ColorIndex = 3
[birth].Interior.Pattern = xlSolid
If MsgBox("Date of Birth is empty; Please enter now", vbYesNo) = vbYes Then
userInput = vbNullString
userInput = Application.InputBox("Enter DOB", "DOB in mm/dd/yyyy format", Default:=Format(Date, "mm/dd/yyyy"), Type:=2)
If IsDate(userInput) Then
[birth].Value = userInput
[birth].Interior.ColorIndex = 2
End If
End If
End If
If IsEmpty(PANNo) Then
[PANNo].Interior.ColorIndex = 3
[PANNo].Interior.Pattern = xlSolid
If MsgBox("PAN No. is empty;Please enter now", vbYesNo) = vbYes Then
userInput = vbNullString
userInput = Application.InputBox("Enter PAN No.", "PAN No.", Type:=2)
If Len(userInput) = 10 Then
[PANNo].Value = userInput
[PANNo].Interior.ColorIndex = 2
End If
End If
End If
End Sub
https://docs.google.com/file/d/0B23eJ2xd9ODybDdROVo4dUxLVjA/edit?usp=sharing
No comments:
Post a Comment