Which way is faster? If elseif or select case

前端 未结 6 1284
陌清茗
陌清茗 2020-12-20 14:13

For the following code,

If Sheets(\"sheet1\").Range(\"A1\").Value = \"option_1\" Then
    Sheets(\"sheet1\").Range(\"A1\").Value = \"option_2\"
ElseIf Sheets         


        
6条回答
  •  悲哀的现实
    2020-12-20 14:37

    1. Case statements are supposed to minimize the number of times the processor attempts to change its command location. Doing so will cause it to waste clock cycles until the correct commands are referenced. Unless you're writing something that needs to be extremely optimized you won't notice the difference.
    2. I lean towards case statements because they are easier to read. (less to read => easier to read)
    3. If this is the exact data you are using, you can split the value on '_' and increment the last digit 'mod' the highest value possible. Combine the strings back together to get your result.

提交回复
热议问题