Dears,
It is my very first question in this forum and would be very glad if you could 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.
I wrote the below code, but it doesn't work because there is no loop and no vlookup as you see.
The below code only works for line 34, but I want from Excel that it checks every line from C18 until C267, and when any of these cells are called "Header", I want that Excel merges the columns E-W on that line.
Would you be able to help me ?
My best regards, Alisan
Sub mergeCellsBasedOnCriteria()
Dim val As String
Dim rng As Range
Set rng = Range("E34:W34")
For Each cell In rng
val = "Header"
Next cell
With rng
.Merge
.Value = Trim(val)
.Font.Bold = True
.WrapText = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
It is my very first question in this forum and would be very glad if you could 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.
I wrote the below code, but it doesn't work because there is no loop and no vlookup as you see.
The below code only works for line 34, but I want from Excel that it checks every line from C18 until C267, and when any of these cells are called "Header", I want that Excel merges the columns E-W on that line.
Would you be able to help me ?
My best regards, Alisan
Sub mergeCellsBasedOnCriteria()
Dim val As String
Dim rng As Range
Set rng = Range("E34:W34")
For Each cell In rng
val = "Header"
Next cell
With rng
.Merge
.Value = Trim(val)
.Font.Bold = True
.WrapText = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub