Hi all!
So I am trying to merge cells and unmerge them to the original state they were created as. I am using a VBA code to perform this. Here is the program:
Private Sub sub4(ByVal Target As Range)
If Target.Address = "$D$21" Then ' Assuming drop-down is in cell D21
If IsNumeric(Target.Value) Then
Application.DisplayAlerts = False
If Target.Value = 2 Then
Range("C21:C33").merge
Else
Range("C21:C33").UnMerge
Range("C21:C26").merge
Range("C21:C26").WrapText = False
Range("C21:C26").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C28:C33").Borders(xlEdgeTop).LineStyle = xlContinuous
Range("C28:C33").UnMerge
Range("C28:C33").merge
Range("C28").Value = "-"
Range("C28:C33").Borders(xlEdgeBottom).LineStyle = xlContinuous
If Target.Value = 3 Then
Range("C21:C40").merge
Else
Range("C21:C40").UnMerge
Range("C21:C26").merge
Range("C21:C26").WrapText = False
Range("C21:C26").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C28:C33").merge
Range("C28:C33").WrapText = False
Range("C28:C33").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C35:C40").merge
Range("C35:C40").WrapText = False
Range("C35:C40").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C28").Value = "-"
Range("C35").Value = "-"
Range("C28:C33").Borders(xlEdgeBottom).LineStyle = xlContinuous
End If
End If
Application.DisplayAlerts = True
End If
End If
End Sub
Ok so the code is performing this action:
1 is the default setting in the dropdown box
2 will merge both cells together
3 will merge all three cells together
The code works flawless for this action. It is exactly what I want. So I also want to be able to toggle back and forth from each dropdown value and it will revert back to that particular number. If I set it to merge 3 cells but I actually meant to make it 2 cells, I want it to go back to how dropdown 2 looks like. See the problem below:
When I go from 3 to 1 it changes perfect.
THE PROBLEM:
When I go from 3 to 2 it shows absolutely no change at all. Why??? Is the code wrong somewhere??
Thanks for your help!!
So I am trying to merge cells and unmerge them to the original state they were created as. I am using a VBA code to perform this. Here is the program:
Private Sub sub4(ByVal Target As Range)
If Target.Address = "$D$21" Then ' Assuming drop-down is in cell D21
If IsNumeric(Target.Value) Then
Application.DisplayAlerts = False
If Target.Value = 2 Then
Range("C21:C33").merge
Else
Range("C21:C33").UnMerge
Range("C21:C26").merge
Range("C21:C26").WrapText = False
Range("C21:C26").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C28:C33").Borders(xlEdgeTop).LineStyle = xlContinuous
Range("C28:C33").UnMerge
Range("C28:C33").merge
Range("C28").Value = "-"
Range("C28:C33").Borders(xlEdgeBottom).LineStyle = xlContinuous
If Target.Value = 3 Then
Range("C21:C40").merge
Else
Range("C21:C40").UnMerge
Range("C21:C26").merge
Range("C21:C26").WrapText = False
Range("C21:C26").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C28:C33").merge
Range("C28:C33").WrapText = False
Range("C28:C33").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C35:C40").merge
Range("C35:C40").WrapText = False
Range("C35:C40").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("C28").Value = "-"
Range("C35").Value = "-"
Range("C28:C33").Borders(xlEdgeBottom).LineStyle = xlContinuous
End If
End If
Application.DisplayAlerts = True
End If
End If
End Sub
Ok so the code is performing this action:
1 is the default setting in the dropdown box
2 will merge both cells together
3 will merge all three cells together
The code works flawless for this action. It is exactly what I want. So I also want to be able to toggle back and forth from each dropdown value and it will revert back to that particular number. If I set it to merge 3 cells but I actually meant to make it 2 cells, I want it to go back to how dropdown 2 looks like. See the problem below:
When I go from 3 to 1 it changes perfect.
THE PROBLEM:
When I go from 3 to 2 it shows absolutely no change at all. Why??? Is the code wrong somewhere??
Thanks for your help!!