|
-
May 15th, 2013, 11:46 AM
#1
Thread Starter
Registered User
Simple Array Script help
Hi there
Just need to insert 19 different arrays into my script, but still having trouble. Its unique serial numbers with a name to each.
Code:
SALGA = Array("0301/4535/0000", "0550/4535/0000") 'Salga
Sec = Array("0301/4213/0000", "0550/4213/0000", "0700/4213/0000")
TarW = Array("0101/4515/0000", "0401/4515/0000") 'Target Women
TarY = Array("0003/4517/0000", "0401/4517/0000") 'Target Youth
Train = Array("0211/4523/0000", "0501/4523/0000") 'Training
And i want to insert them into this:
Code:
myAry = Array("0003/3857/0000", "0101/3857/0000", "0201/3857/0000", "0301/3857/0000", "0401/3857/0000", _
"0550/3857/0000", "0601/3857/0000", "0700/3857/0000", "0003/6063/0000", "0101/6063/0000", "0201/6063/0000", _
"0301/6063/0000", "0401/6063/0000", "0550/6063/0000", "0601/6063/0000", "0700/6063/0000")
For i = LBound(myAry) To UBound(myAry)
If Range("B" & RowNumbr) = myAry(i) Then
Qs = MsgBox("The current vote you created is allocated on Vehicle. Is This Correct?", _
vbYesNo + vbQuestion, "VALIDATE")
If Qs = vbNo Then
Range("C" & RowNumbr) = "No"
ElseIf Qs = vbYes Then
Range("C" & RowNumbr) = "Yes"
End If
Exit For
End If
If i = UBound(myAry) Then MsgBox "Vote Number Not found", vbCritical, "WARNING"
Next
This code works perfectly. My aim is to let the user insert the serial number via input box, then this code should run and display under which name it falls, and then display the name of the serial number, followed by an interaction with the MsgBox commands as seen in the example above. Then when no values are found, it should display the last message in the above script..
Is there any advise? I am very new to VBA scripts
-
May 15th, 2013, 04:40 PM
#2
Re: Simple Array Script help
you want to check if one serial number, input by user, is in the array?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 16th, 2013, 12:33 AM
#3
Thread Starter
Registered User
Re: Simple Array Script help
Yes, within all those arrays
-
May 16th, 2013, 08:13 AM
#4
Re: Simple Array Script help
you can try like this to see if it suits your needs
Code:
salga = Array("0301/4535/0000", "0550/4535/0000") 'Salga
sec = Array("0301/4213/0000", "0550/4213/0000", "0700/4213/0000")
tarw = Array("0101/4515/0000", "0401/4515/0000") 'Target Women
tary = Array("0003/4517/0000", "0401/4517/0000") 'Target Youth
train = Array("0211/4523/0000", "0501/4523/0000") 'Training
ReDim myarr(4) ' change to suit if more arrays are used
myarr(0) = salga
myarr(1) = sec
myarr(2) = tarw
myarr(3) = tary
myarr(4) = train
spec = InputBox("enter value", "Serial No", "0101/4515/0000")
For i = 0 To UBound(myarr)
For j = 0 To UBound(myarr(i))
If myarr(i)(j) = spec Then fnd = True: Exit For
Next
If fnd Then Exit For
Next
If fnd Then
MsgBox "The current vote you created is allocated on Vehicle."
Else
MsgBox "Vote Number Not found", vbCritical, "WARNING"
End If
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 16th, 2013, 12:43 PM
#5
Thread Starter
Registered User
Re: Simple Array Script help
Now that is what i was trying to accomplish . Thank you for that. Now i just need to create a script to justify exactly which array was located within this input box.
Once again, thank you
-
May 16th, 2013, 04:32 PM
#6
Re: Simple Array Script help
try like
Code:
salga = Array("0301/4535/0000", "0550/4535/0000") 'Salga
sec = Array("0301/4213/0000", "0550/4213/0000", "0700/4213/0000")
tarw = Array("0101/4515/0000", "0401/4515/0000") 'Target Women
tary = Array("0003/4517/0000", "0401/4517/0000") 'Target Youth
train = Array("0211/4523/0000", "0501/4523/0000") 'Training
ReDim myarr(4) ' change to suit if more arrays are used
redim alist(4)
myarr(0) = salga: alist(0) = "salga"
myarr(1) = sec: alist(1) = "sec"
myarr(2) = tarw: alist(2) = "tarw"
myarr(3) = tary: alist(3) = "tary"
myarr(4) = train: alist(4) = "train"
spec = InputBox("enter value", "Serial No", "0101/4515/0000")
For i = 0 To UBound(myarr)
For j = 0 To UBound(myarr(i))
If myarr(i)(j) = spec Then fnd = True: location = alist(i): Exit For
Next
If fnd Then Exit For
Next
If fnd Then
MsgBox "The current vote you created is allocated on Vehicle. at " & location
Else
MsgBox "Vote Number Not found", vbCritical, "WARNING"
End If
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|