So far I have written this much code . This is for the first time I am coding in VBA . I dont know what to do . I got the logic but dont know how to do it . I am also having problem in listing down all the reservation number on the form type template with all the required information on it .
I have commented some of the things that I am not sure how to do it . Please add your code too . what you think is right
. THanks
CODE IN VBA
Sub VerifyReserveNumber()
Dim reserveSysArray As Variant 'An array used for user input
Dim foundPAFC As Boolean 'true if PA and FC of existing list matches with the entered number
Dim uPA, uFc, uNum ' User PlanArea , User FunctionCode , User Number
Dim ws As Worksheet
Dim lastRow As Integer
Dim projectID As String
Dim rn As String ' Single Cell's Reservation Number (parent System)
Dim reserveNum As Range 'Parent System Number list for current sheet (Equipement location P column
Dim arrSysNum As Variant 'an array that stores the parts of a system number eg. plan area, PFC, number
Dim planArea As String
Dim PFC As Long
Dim num As Long 'stores the number portion of the system number eg. (plan area - PFC - number)
foundPAFC = False
' Input box will be prompt to user to enter the reservation number he is looking for
SearchVal = InputBox("Enter the Validation/Searching value", "Enter Reservation Number")
' If user leaves it blank , box will appear saying no input found
If Len(SearchVal) = 0 Or SearchVal = " " Then MsgBox "No input found ", , "No Search": Exit Sub
reserveSysArray = Split(SearchVal, "-")
uPA = reserveSysArray(0)
uFc = reserveSysArray(1)
uNum = reserveSysArray(2) ' might contain "053A" or "053 only" for eg.
If IsNumeric(uNum) = False Then ' means it contain last alphabet and digits both
uNum = Left(uNum, Len(uNum) - 1) ' Will remove the last alphabet Character from the string
If Len(uNum) > 3 And IsNumeric(uNum) = True Then
MsgBox "Non-Maintained Number : No validation required for that ", , "Exiting": Exit Sub
' ***Start Iterating through Each Worksheets and list down all the reserve number which meet conditions ***
For Each ws In ThisWorkbook.Worksheets 'will check each worksheet one by one in whole workbook
HiddenState = ws.Visible 'store the visibility state of the sheet.
ws.Visible = True 'Visibility turn on temporarily if its off for checking whole data
Set reserveNum = ws.Range("Position_Equip_Loc2")
For Each rn In reserveNum
'rn is one single reserve number
arrSysNum = Split(rn, "-")
planArea = arrSysNum(0)
PFC = arrSysNum(1)
num = arrSysNum(2)
If planArea = uPA And PFC = uFc Then
foundPAFC = True 'if true then list down all the reserve num meeting that condition
'???????
'????? '??? also include PROJECTID for the following row too ,
'***** If possible show it on form " I have no idea
' ? ????
End If
Next
Next
End Sub