VBA for merging and centering cells and including text based on a dynamic range and text reference

ConsultantKev

New Member
Joined
Dec 3, 2018
Messages
1
Hello all,

I am creating a dynamic Gantt chart for an upcoming workshop in which several team members will view and collaboratively edit the start and end dates of various work streams to align on a work plan.

I have a worksheet with tasks in column B, the task's respective start date in column c, and the end date in column D. In columns E-AB above the rows for each task, I have semi-monthly dates (1st and 15th of each month for one year).

The cells in columns E-AB to the right of each task are conditionally formatted to fill based on the start and ends dates (columns C and D, respectively) and the reference timeline above it.

Now, I would like the cells in the shaded bars describing the duration of each task to merge, and center and show the name of the task included in column B. I've tried using VBA with some codes found online, but Im having trouble finding a code that will work with a start and end cell reference, and also one that will allow me to fill the now merged cell with a text from a reference cell.

Can anyone help?

88CtHzy

88CtHzy

excel.png
[/URL][/IMG]
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I am assuming it will need some adjustment but this should get you started

Code:
Sub Test()

myRow = 14
myLastRow = Cells(Rows.Count, "B").End(xlUp).Row

For n = myRow To myLastRow

For i = 5 To 30

If Cells(n, i).Interior.TintAndShade <> 0 Then
myStart = i
Exit For
End If

Next i

For e = myStart To 30
If Cells(n, e).Interior.TintAndShade = 0 Then
myEnd = e - 1
Exit For
End If
Next e

Cells(n, myStart).Value = Cells(n, 2).Value
Range(Cells(n, myStart), Cells(n, myEnd)).Select

With Selection
        .Merge
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
End With

Next n

End Sub
 
Last edited:
Upvote 0
For reference, if you merge the cells you will destroy your conditional formatting.
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top