Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro or VBA to Bold first 3 characters of a cell in the entirecolumn

My macro to bold the first three characters of a cell works great but
I am struggling with enhancing the macro to automatically repeat for
the entire column "C" instead of running it cell by cell. Ideally,
the macro would run on open, but I'll settle for running it on
command.

Any help is greatly appreciated!

Dim StartChar As Integer
Dim BoldLen As Integer
StartChar = 3
BoldLen = 5
ActiveCell.Characters(StartChar, BoldLen).Font.Bold = True
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default Macro or VBA to Bold first 3 characters of a cell in the entire co

Hi,

Copy this code into ThisWorkbook, not a module:

Private Sub Workbook_Open()

Dim Iloop As Double
Dim RowCount As Double
Dim StartChar As Integer
Dim BoldLen As Integer

StartChar = 3
BoldLen = 5
RowCount = Cells(Rows.Count, "C").End(xlUp).Row
For Iloop = 1 To RowCount
Cells(Iloop, "C").Characters(StartChar, BoldLen).Font.Bold = True
Next Iloop

End Sub

This will bold characters 3 through 5, not the first 3.
--
Ken Hudson


"imelda1ab" wrote:

My macro to bold the first three characters of a cell works great but
I am struggling with enhancing the macro to automatically repeat for
the entire column "C" instead of running it cell by cell. Ideally,
the macro would run on open, but I'll settle for running it on
command.

Any help is greatly appreciated!

Dim StartChar As Integer
Dim BoldLen As Integer
StartChar = 3
BoldLen = 5
ActiveCell.Characters(StartChar, BoldLen).Font.Bold = True

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Macro or VBA to Bold first 3 characters of a cell in the entire column

Another one

Sub test()
Dim StartChar As Long
Dim BoldLen As Long
Dim rng As Range, ra As Range, cell As Range

StartChar = 3
BoldLen = 5

On Error Resume Next
Set rng = Range("C:C").SpecialCells(xlCellTypeConstants, 23)
If rng Is Nothing Then Exit Sub

For Each ra In rng.Areas
For Each cell In ra
cell.Select
cell.Font.Bold = False
If Len(cell) = StartChar Then
cell.Characters(StartChar, BoldLen).Font.Bold = True
End If
Next
Next

End Sub

Your description and code example contradict in terms of which characters to
make bold, I've gone with the latter.

Regards,
Peter T



"imelda1ab" wrote in message
...
My macro to bold the first three characters of a cell works great but
I am struggling with enhancing the macro to automatically repeat for
the entire column "C" instead of running it cell by cell. Ideally,
the macro would run on open, but I'll settle for running it on
command.

Any help is greatly appreciated!

Dim StartChar As Integer
Dim BoldLen As Integer
StartChar = 3
BoldLen = 5
ActiveCell.Characters(StartChar, BoldLen).Font.Bold = True



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Macro or VBA to Bold first 3 characters of a cell in the entirecolumn

On Mar 6, 5:40*pm, "Peter T" <peter_t@discussions wrote:
Another one

Sub test()
Dim StartChar As Long
Dim BoldLen As Long
Dim rng As Range, ra As Range, cell As Range

* * StartChar = 3
* * BoldLen = 5

* * On Error Resume Next
* * Set rng = Range("C:C").SpecialCells(xlCellTypeConstants, 23)
* * If rng Is Nothing Then Exit Sub

* * For Each ra In rng.Areas
* * * * For Each cell In ra
* * * * * * cell.Select
* * * * * * cell.Font.Bold = False
* * * * * * If Len(cell) = StartChar Then
* * * * * * * * cell.Characters(StartChar, BoldLen).Font.Bold = True
* * * * * * End If
* * * * Next
* * Next

End Sub

Your description and code example contradict in terms of which characters to
make bold, I've gone with the latter.

Regards,
Peter T

"imelda1ab" wrote in message

...



My macro to bold the first three characters of a cell works great but
I am struggling with enhancing the macro to automatically repeat for
the entire column "C" instead of running it cell by cell. *Ideally,
the macro would run on open, but I'll settle for running it on
command.


Any help is greatly appreciated!


Dim StartChar As Integer
Dim BoldLen As Integer
StartChar = 3
BoldLen = 5
ActiveCell.Characters(StartChar, BoldLen).Font.Bold = True- Hide quoted text -


- Show quoted text -


Thank you both SO, SO VERY much! It works perfectly! Yes, I
contradicted myself and pasted the wrong code. The 3,5 was contained
in the the code I found in my search through groups (love the groups)
and saved in my "Keep this so I don't have to look for it or remember
which spreadsheet I used it in again" formula document. Thanks again,
you guys rock.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to copy row to another worksheet if cell is in bold type. [email protected][_2_] Excel Programming 2 June 8th 07 09:15 AM
Join bold and non-bold text in one cell bkincaid Excel Discussion (Misc queries) 3 March 21st 06 12:58 AM
Bold characters will not print! Dragoon_42 Excel Discussion (Misc queries) 2 June 3rd 05 10:12 PM
How do you make some characters in a cell bold and some not? tracman Excel Discussion (Misc queries) 4 March 28th 05 05:17 AM
Cell Truncates to 255 characters in Macro Andrew[_11_] Excel Programming 1 September 3rd 03 09:22 PM


All times are GMT +1. The time now is 09:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"