Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Below are two snippets of code, both producing the same results.
Which is more elegant and proper to use and easiest to understand? (I realize the limitations of nested IF's). Being relatively new to VBA (this is my first attempt at code) - I'm curious to know what's more acceptable. Thanks, -Tony (code 1) 'ethyl round txt_ethy = Application.WorksheetFunction.Round(txt_ethy, 2) 'ethyl ether flag Worksheets("con1").Cells(131, 4).Value = txt_ethy Worksheets("con1").Range("D134:D138").ClearContent s If txt_ethy_flags = "B" Then Worksheets("con1").Cells(134, 4).Value = txt_ethy_flags ElseIf txt_ethy_flags = "D" Then Worksheets("con1").Cells(135, 4).Value = txt_ethy_flags ElseIf txt_ethy_flags = "E" Then Worksheets("con1").Cells(136, 4).Value = txt_ethy_flags ElseIf txt_ethy_flags = "J" Then Worksheets("con1").Cells(137, 4).Value = txt_ethy_flags ElseIf txt_ethy_flags = "U" Then Worksheets("con1").Cells(138, 4).Value = txt_ethy_flags ElseIf txt_ethy_flags = "UB" Then UFlag = Trim(Mid(txt_ethy_flags, 1, 1)) BFlag = Trim(Mid(txt_ethy_flags, 2, 1)) Worksheets("con1").Cells(138, 4).Value = UFlag Worksheets("con1").Cells(134, 4).Value = BFlag ElseIf txt_ethy_flags = "JB" Then BFlag = Trim(Mid(txt_ethy_flags, 1, 1)) JFlag = Trim(Mid(txt_ethy_flags, 2, 1)) Worksheets("con1").Cells(134, 4).Value = BFlag Worksheets("con1").Cells(137, 4).Value = JFlag Else ' do nothing End If (code 2) 'ethyl round txt_ethy = Application.WorksheetFunction.Round(txt_ethy, 2) 'ethyl ether flag Worksheets("con1").Cells(131, 4).Value = txt_ethy Worksheets("con1").Range("D134:D138").ClearContent s Select Case txt_ethy_flags Case "B" Worksheets("con1").Cells(134, 4).Value = txt_ethy_flags Case "D" Worksheets("con1").Cells(135, 4).Value = txt_ethy_flags Case "E" Worksheets("con1").Cells(136, 4).Value = txt_ethy_flags Case "J" Worksheets("con1").Cells(137, 4).Value = txt_ethy_flags Case "U" Worksheets("con1").Cells(138, 4).Value = txt_ethy_flags Case "UB" UFlag = Trim(Mid(txt_ethy_flags, 1, 1)) BFlag = Trim(Mid(txt_ethy_flags, 2, 1)) Worksheets("con1").Cells(138, 4).Value = UFlag Worksheets("con1").Cells(134, 4).Value = BFlag Case "JB" BFlag = Trim(Mid(txt_ethy_flags, 1, 1)) JFlag = Trim(Mid(txt_ethy_flags, 2, 1)) Worksheets("con1").Cells(134, 4).Value = BFlag Worksheets("con1").Cells(137, 4).Value = JFlag End Select |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
+ or - % Results | Excel Worksheet Functions | |||
IF/THEN Results | Excel Discussion (Misc queries) | |||
More MIN() results..? | Excel Worksheet Functions | |||
Conditional Sum Argument results do not equal cell results Excel | Excel Worksheet Functions | |||
How can I list the results of my macro without overwritng previous results? | Excel Programming |