Create text and keep formatting from range of cells

jonybandana

New Member
Joined
Dec 16, 2022
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hi everyone!
I have the following table:

TaskOwnerDateConcat1 ("RESP" + Owner)Concat2 ("FCST" + Date)Concat3 (everything)
Do something.Greg24/10/2024Owner: GregForecast: 24-10-24Do something. Owner: Greg Forecast: 24-10-24
Do this.Mark1/11/2024Owner: MarkForecast: 01-11-24Do this. Owner: Mark Forecast: 01-11-24
Do that.Jen15/1/2025Owner: JenForecast: 15-01-25Do that. Owner: Jen Forecast: 15-01-25

I have this set up because I have to send minutes of our meetings at my job, and this makes the job of typing names and dates and saves me from typing "FORECAST" and "OWNER" a millon times every time I send a minute.

I also have a third column that concatenates everything, so I can just copy it over to work and will look like regular text, and it wont have "tab" characters between every "column", so it would look like this bulleted in Word:
  • Do something Owner: Greg Forecast: 24-10-24
  • Do this Owner: Mark Forecast: 01-11-24
  • Do that Owner: Jen Forecast: 15-01-25
My only issue here is that this way I do not keep the formattin (The bolding in the last two columns), and I would like to keep it.

I looked into text boxes, but they don't really work like that. Is there any way I would get something like this instead?
  • Do something Owner: Greg Forecast: 24-10-24
  • Do this Owner: Mark Forecast: 01-11-24
  • Do that Owner: Jen Forecast: 15-01-25
Thanks for any help you can give me!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Research indicates that this is not possible using cell formulas or functions. You would have to resort to vba. In F2 (?) down, you'd replace what you have with a vba function call. That function would concatenate col(A) row with "Owner " & col(B) & "Forecast " & col(C) along with the required spaces. The function would also format your string portions. This would also eliminate the need for the concat columns you have now. If you're willing to use vba this should be quite simple. You'd need to id the columns as they have no headers in your post.
 
Upvote 0
Update: In all my years of dabbling in vba I never tried to bold parts of a string as I suggested. Turns out it is not possible. So your options are to
- use vba to bold part of your fully concatenated cell col(F)? so that you can copy that for your email text (and hope the formatting carries over)
- use vba to build your email body as html (not plain text) and send the message in one go (or just display it). This assumes you'd be using Outlook.
 
Upvote 0
Hi all, here is my attempt, it inserts the concatenated and formatted text in the column D. The code is to be pasted in the sheet module (right click on the sheet tab, choose view code, paste the following code).
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Set rng = Intersect(Target, Me.Range("A2:C" & Me.Cells(Me.Rows.Count, "A").End(xlUp).Row))
    
    If Not rng Is Nothing Then
        Application.EnableEvents = False
        
        Dim cell As Range
        For Each cell In rng
            If Not Intersect(cell, Me.Columns("A:C")) Is Nothing Then
                Dim task As String
                Dim Owner As String
                Dim dateForecast As String
                Dim concat1 As String
                Dim concat2 As String
                
                task = Me.Cells(cell.Row, "A").Value
                Owner = Me.Cells(cell.Row, "B").Value
                dateForecast = Format(Me.Cells(cell.Row, "C").Value, "dd-mm-yy") ' Formatta la data
                
                Me.Cells(cell.Row, "D").ClearFormats
                concat1 = "Owner: " & Owner
                concat2 = "Forecast: " & dateForecast
              
                Me.Cells(cell.Row, "D").ClearFormats
                Me.Cells(cell.Row, "D").Value = Chr(149) & " " & task & " " & concat1 & " " & concat2
                                
                Dim startPos As Long
                startPos = Len(task) + 3
                Me.Cells(cell.Row, "D").Characters(startPos, Len(concat1) + 1).Font.Bold = True
                Me.Cells(cell.Row, "D").Characters(startPos + Len(concat1) + 2, Len(concat2)).Font.Bold = True
            End If
        Next cell
        
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Looks OK but I just glanced over it. Since this is about sending emails, I have to wonder why not just automate that and do the formatting in the htmlBody of the email? That would sort of kill 2 birds with one stone so to speak. In other words, the code could create and send (or just display for review) the email with the body text formatted as per the requirements of this thread. That would eliminate the cell formatting code part, and the need to copy and paste the result of that code into the email.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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