LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Same Results - which is better?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
+ or - % Results mahlandj Excel Worksheet Functions 4 March 4th 10 12:15 AM
IF/THEN Results bgrayduck Excel Discussion (Misc queries) 1 May 28th 09 04:08 PM
More MIN() results..? Mac Excel Worksheet Functions 1 October 16th 07 03:52 PM
Conditional Sum Argument results do not equal cell results Excel Randy R Mullins Excel Worksheet Functions 3 August 9th 06 07:16 PM
How can I list the results of my macro without overwritng previous results? mattip Excel Programming 3 November 28th 03 03:45 AM


All times are GMT +1. The time now is 09:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"