VBA Bold Formatting

brkkrkmz112

New Member
Joined
Oct 24, 2016
Messages
43
Hi,

I am trying to automatize the format used for daily updates. I want that when I make revisions, before my comments I want to add a draft such as "*[Date of Today]" and it should be bold.

The problem is that for new updates everything is okay but for the format of previous updates(Being bold) is ruined after this addition. I mean it removes bold formatting.

You can see examples below and my code as well . Thank you in advance.


What it is done. What it should be..
Capture.PNG
Capture1.PNG


VBA Code:
Option Explicit

Sub burak()

Dim a As Date, b As String, c As String, d As String, k As Integer

Application.CutCopyMode = False

a = Now()
b = Format(a, "dd-mm-yy")
c = CStr(b)

k = Len(Selection(1))

Selection(1).Value = Selection(1).Value & Chr(10) & "*[" & c & "] "
Selection(1).Characters(Start:=k + 2, Length:=11).Font.Bold = True

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
See if this does what you want. Test with a copy of your data.

VBA Code:
Sub AddBoldDate()
  Dim sBold As String
  Dim aBold As Variant
  Dim i As Long, j As Long, slen As Long
  
  With ActiveCell
    slen = Len(.Value)
    For i = 1 To slen
      If .Characters(i, 1).Font.Bold Then
        sBold = sBold & " " & i
        j = 0
        Do While .Characters(i + j, 1).Font.Bold And (i + j) <= slen
          j = j + 1
        Loop
        sBold = sBold & " " & j
        i = i + j - 1
      End If
    Next i
    .Value = .Value & " *[" & Format(Date, "dd-mm-yy]")
    aBold = Split(sBold & " " & slen + 2 & " 11")
    For i = 1 To UBound(aBold) Step 2
      .Characters(aBold(i), aBold(i + 1)).Font.Bold = True
    Next i
  End With
End Sub
 
Upvote 0
Here is another macro that you can test...
VBA Code:
Sub AddBoldedDate()
  Dim L As Long
  With ActiveCell
    L = Len(.Value)
    .Characters(L + 1).Text = vbLf & Format(Now(), "\*\[dd-mm-yy] ")
    .Characters(L + 2, 11).Font.Bold = True
  End With
End Sub
 
Upvote 0
@Peter... If your are testing my code, make sure you have the latest version as I made some changes after I noticed you logged on.
 
Upvote 0
@Peter... If your are testing my code, make sure you have the latest version as I made some changes after I noticed you logged on.
Hi Rick. Yes, I did have the old code which was truncating a character. ;) New code looks good & much simpler than my attempt. (y)

Hope you are keeping well. From where we sit in Australia, things look pretty scary in the US! ? (& much of the rest of the world BTW)
 
Upvote 0
New code looks good & much simpler than my attempt. (y)
You know me... compact code and all that. ?


Hope you are keeping well. From where we sit in Australia, things look pretty scary in the US! ? (& much of the rest of the world BTW)
Yes, my family and I are keeping well... and I hope the same for you and yours as well. We pretty much stay in the house all day long every day (being in my mid-70s, I am in the "vulnerable" group). And yes, things are scary here... unfortunately, the majority of elected leaders are not scared enough though. States are starting to reopen way to soon in my opinion. These leaders seem to forget if you open a small business establishment in an area where the infection rate is low (main reason given for allowing reopenings) that people from outside your area where the infection rate is higher may/will travel into your area to avail themselves of the businesses that reopened, possibly bring the infection in with them. I see this as a major problem with businesses near a state's border with another state... any such imported virus activity could then migrate inward from there. Personally, I don't see how anything can be considered safe to do until a vaccine is created and widely available. How are things in Australia? Our news cycle here in the US is completely dominated by US virus news so we don't hear about anything in detail that is happening anywhere else. It is as if there is no other news happening any more.
 
Upvote 0
Thanks you both sirs. They work as I want. But here ı have another question. It is just for one type of format change. Lets say I have multiple formattings, such as some of them bold or just in different colour or has font effect etc etc. Can not we do just like pressing F2 and making changes and pressing enter? Is there any other way to add something while keeping the old stuff as it is.
 
Upvote 0
Lets say I have multiple formattings, such as some of them bold or just in different colour or has font effect etc etc. Can not we do just like pressing F2 and making changes and pressing enter? Is there any other way to add something while keeping the old stuff as it is.


Isn't that exactly what Rick's code from post #3 does?

Before code:
1589370315231.png



After code:
1589370359201.png
 
Upvote 0
Yes but it does not work for texts longer than 255 characters :(
In that case you may have to decide on what formatting characteristics that you wanted to preserve and 'harvest' them and reapply after adding the extra text like I did with the bold in the code in post #2. Could be a very big task if there are lots of characteristics that you wanted to capture! :eek:
 
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

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