title: Excel VBA - Worksheet Event
body: <p>I want excel vba code on worksheet event my question is that i have data from g8:g28 and if g8 = 2  then unmerge a8:a10: and merge a8:a9  and if g8=3 then then unmerge a8:a10: and merge a8:a10</p>
  <p>if g9 = 2  then unmerge a8:a10: and merge a9:a10  and if g9=3 then then unmerge a8:a10 and merge a9:a11
  Similar this is with all data from g8:g28</p>
  <p>I have developed some below code but I do not understand that how should these code can be concise and apply on cell g8 to g28</p>
  <pre><code>Option Explicit
  Private Sub Worksheet_Change(ByVal Target As Range)
  Application.DisplayAlerts = False
  
  Select Case [G8].Value
      Case Is = 1
          Range(&quot;A8:A10,F8:F10,G8:G10&quot;).UnMerge
      Case Is = 2
          Range(&quot;A8:A10,F8:F10,G8:G10&quot;).UnMerge
          Range(&quot;A8:A9,F8:F9,G8:G9&quot;).Merge
      Case Is = 3
          Range(&quot;A8:A10,F8:F10,G8:G10&quot;).UnMerge
          Range(&quot;A8:A10,F8:F10,G8:G10&quot;).Merge
    End Select
  
  On Error Resume Next
  
  
  Application.DisplayAlerts = True
  End Sub
  </code></pre>