Excel VBA - Worksheet Event

Viewed 38

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

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

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

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.DisplayAlerts = False

Select Case [G8].Value
    Case Is = 1
        Range("A8:A10,F8:F10,G8:G10").UnMerge
    Case Is = 2
        Range("A8:A10,F8:F10,G8:G10").UnMerge
        Range("A8:A9,F8:F9,G8:G9").Merge
    Case Is = 3
        Range("A8:A10,F8:F10,G8:G10").UnMerge
        Range("A8:A10,F8:F10,G8:G10").Merge
  End Select

On Error Resume Next


Application.DisplayAlerts = True
End Sub
0 Answers
Related