dan_l
Active Member
I need a good way to achieve this.
I've got a UDF that looks at a cell and evaluates the parts of the string against a couple of vlookup tables. Under good circumstances, the results of the look up are run through a formula. In the event that one or more of the parts of the string is bad, I'd like the output to instead tell the user which parts are bad.
Here's the idea. This isn't even the 'live' code, it's just a paired down example I'm screwing with:
[pre]
[/pre]
So on/so forth. But what would be the best way to do this?
I've got a UDF that looks at a cell and evaluates the parts of the string against a couple of vlookup tables. Under good circumstances, the results of the look up are run through a formula. In the event that one or more of the parts of the string is bad, I'd like the output to instead tell the user which parts are bad.
Here's the idea. This isn't even the 'live' code, it's just a paired down example I'm screwing with:
[pre]
Code:
Dim opt1, opt2, opt3, opt4 As String
Dim c1, c2, c3, c4 As Integer
opt1 = Left(sim, 2)
opt2 = Mid(sim, 3, 2)
opt3 = Mid(sim, 5, 2)
opt4 = Right(sim, 2)
c1 = Application.WorksheetFunction.VLookup(opt1, [comp1], 2, False)
c2 = Application.WorksheetFunction.VLookup(opt2, [comp2], 2, False)
c3 = Application.WorksheetFunction.VLookup(opt3, [comp3], 2, False)
c4 = Application.WorksheetFunction.VLookup(opt4, [comp4], 2, False)
simresult = c1+c2+c3+c4
I think maybe I could create a variable called string and do it with if/then
so
dim error as string
dim errorcount as int
error = ""
errorcount = 0
if c1 = "" then
error = switch(errorcount = 0, error & "Error 1",errorcount=>1,error & "/" & "Error 1")
end if
if c2 = "" then
error = switch(errorcount = 0, error & "Error 2",errorcount=>1,error & "/" & "Error 2")
end if
So on/so forth. But what would be the best way to do this?