Dear friends, I would like to ask you the following;
I need to write a macro which looks up to column C (A dropdown menu, which is selected manually), and if the column C is called "Header", I want that Macro merges the cells between E and W on that specific line.
For this condition, I have the below code which works very fine :
Sub loopandMarge()
Dim lastrow As Long, I As Long
lastrow = Range("C" & Rows.Count).End(xlUp).Row
Application.DisplayAlerts = False
For I = 18 To lastrow
If Cells(I, "C") = "Header" Then
With Range("E" & I & ":W" & I)
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Font.Bold = True
End With
End If
Next I
Application.DisplayAlerts = True
End Sub
However when in column "C" I change the value from the dropdown menu from "Header" to another value, the cells remain merged.
I would like to have a code which can also unmerge the cells, once the value in column "C" change.
Would you be able to help me ?
I need to write a macro which looks up to column C (A dropdown menu, which is selected manually), and if the column C is called "Header", I want that Macro merges the cells between E and W on that specific line.
For this condition, I have the below code which works very fine :
Sub loopandMarge()
Dim lastrow As Long, I As Long
lastrow = Range("C" & Rows.Count).End(xlUp).Row
Application.DisplayAlerts = False
For I = 18 To lastrow
If Cells(I, "C") = "Header" Then
With Range("E" & I & ":W" & I)
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Font.Bold = True
End With
End If
Next I
Application.DisplayAlerts = True
End Sub
However when in column "C" I change the value from the dropdown menu from "Header" to another value, the cells remain merged.
I would like to have a code which can also unmerge the cells, once the value in column "C" change.
Would you be able to help me ?