Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Need help with formatting

Oh Wise Ones,

I have some code to double-click through some selections in a cell. The
problem is the cell won't retain the formatting I have set. The selection
event supersedes the format. So it looks like I have to format in in the code
and I'm not sure of the syntax. I need the selection formatted 16 point and
Bold. Any help would be appreciated. The code is below:

Option Explicit
Private mcolFasteners As Collection

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
'Changes cell B2 value among
'"Royal Sovereign, Sentinel, Hip and Ridge" on double-click.

'Limit the effect to cell B2.
If Target.Address < Range("B2").Address Then
Cancel = False
Exit Sub
End If

On Error GoTo ErrHandler
Dim strBuf As String, v As Variant
'Instatiate and populate a collection
'if not already done.
If mcolFasteners Is Nothing Then
Set mcolFasteners = New Collection
With mcolFasteners
.Add "Royal Sovereign", "Sentinel"
.Add "Hip & Ridge", "Royal Sovereign"
.Add "Sentinel", "Hip & Ridge"
End With
End If

'Get, then clear the current value.
strBuf = LCase(Trim(Target.Text))
Target.Clear

'If it is in our collection, use it as
'an index to the next item in the collection.
For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Exit For
End If
Next v

'If not, just assign the cell one of the values.
If Len(Target.Value) < 1 Then
Target.Value = mcolFasteners(1)
End If

ErrHandler:
Cancel = True

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Need help with formatting


Target.Clear 'removes formatting
Target.ClearContents 'does not remove formatting
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Mike K"

wrote in message
Oh Wise Ones,
I have some code to double-click through some selections in a cell. The
problem is the cell won't retain the formatting I have set. The selection
event supersedes the format. So it looks like I have to format in in the code
and I'm not sure of the syntax. I need the selection formatted 16 point and
Bold. Any help would be appreciated. The code is below:

Option Explicit
Private mcolFasteners As Collection

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
'Changes cell B2 value among
'"Royal Sovereign, Sentinel, Hip and Ridge" on double-click.

'Limit the effect to cell B2.
If Target.Address < Range("B2").Address Then
Cancel = False
Exit Sub
End If

On Error GoTo ErrHandler
Dim strBuf As String, v As Variant
'Instatiate and populate a collection
'if not already done.
If mcolFasteners Is Nothing Then
Set mcolFasteners = New Collection
With mcolFasteners
.Add "Royal Sovereign", "Sentinel"
.Add "Hip & Ridge", "Royal Sovereign"
.Add "Sentinel", "Hip & Ridge"
End With
End If

'Get, then clear the current value.
strBuf = LCase(Trim(Target.Text))
Target.Clear

'If it is in our collection, use it as
'an index to the next item in the collection.
For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Exit For
End If
Next v

'If not, just assign the cell one of the values.
If Len(Target.Value) < 1 Then
Target.Value = mcolFasteners(1)
End If

ErrHandler:
Cancel = True

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Need help with formatting

Jim,
Thank you kind sir! That did the trick.

Mike

"Jim Cone" wrote:


Target.Clear 'removes formatting
Target.ClearContents 'does not remove formatting
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Mike K"

wrote in message
Oh Wise Ones,
I have some code to double-click through some selections in a cell. The
problem is the cell won't retain the formatting I have set. The selection
event supersedes the format. So it looks like I have to format in in the code
and I'm not sure of the syntax. I need the selection formatted 16 point and
Bold. Any help would be appreciated. The code is below:

Option Explicit
Private mcolFasteners As Collection

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
'Changes cell B2 value among
'"Royal Sovereign, Sentinel, Hip and Ridge" on double-click.

'Limit the effect to cell B2.
If Target.Address < Range("B2").Address Then
Cancel = False
Exit Sub
End If

On Error GoTo ErrHandler
Dim strBuf As String, v As Variant
'Instatiate and populate a collection
'if not already done.
If mcolFasteners Is Nothing Then
Set mcolFasteners = New Collection
With mcolFasteners
.Add "Royal Sovereign", "Sentinel"
.Add "Hip & Ridge", "Royal Sovereign"
.Add "Sentinel", "Hip & Ridge"
End With
End If

'Get, then clear the current value.
strBuf = LCase(Trim(Target.Text))
Target.Clear

'If it is in our collection, use it as
'an index to the next item in the collection.
For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Exit For
End If
Next v

'If not, just assign the cell one of the values.
If Len(Target.Value) < 1 Then
Target.Value = mcolFasteners(1)
End If

ErrHandler:
Cancel = True

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Need help with formatting

Try this modified section of your code.

For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Target.Font.Size = 16
Target.Font.Bold = True
Exit For
End If
Next v


"Mike K" wrote:

Oh Wise Ones,

I have some code to double-click through some selections in a cell. The
problem is the cell won't retain the formatting I have set. The selection
event supersedes the format. So it looks like I have to format in in the code
and I'm not sure of the syntax. I need the selection formatted 16 point and
Bold. Any help would be appreciated. The code is below:

Option Explicit
Private mcolFasteners As Collection

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
'Changes cell B2 value among
'"Royal Sovereign, Sentinel, Hip and Ridge" on double-click.

'Limit the effect to cell B2.
If Target.Address < Range("B2").Address Then
Cancel = False
Exit Sub
End If

On Error GoTo ErrHandler
Dim strBuf As String, v As Variant
'Instatiate and populate a collection
'if not already done.
If mcolFasteners Is Nothing Then
Set mcolFasteners = New Collection
With mcolFasteners
.Add "Royal Sovereign", "Sentinel"
.Add "Hip & Ridge", "Royal Sovereign"
.Add "Sentinel", "Hip & Ridge"
End With
End If

'Get, then clear the current value.
strBuf = LCase(Trim(Target.Text))
Target.Clear

'If it is in our collection, use it as
'an index to the next item in the collection.
For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Exit For
End If
Next v

'If not, just assign the cell one of the values.
If Len(Target.Value) < 1 Then
Target.Value = mcolFasteners(1)
End If

ErrHandler:
Cancel = True

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Need help with formatting

Thanks for the response. But apparently the Target.Clear was wiping my
formatting. Target.ClearContents left the formatting intact. The little
things....

Mike

"JLGWhiz" wrote:

Try this modified section of your code.

For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Target.Font.Size = 16
Target.Font.Bold = True
Exit For
End If
Next v


"Mike K" wrote:

Oh Wise Ones,

I have some code to double-click through some selections in a cell. The
problem is the cell won't retain the formatting I have set. The selection
event supersedes the format. So it looks like I have to format in in the code
and I'm not sure of the syntax. I need the selection formatted 16 point and
Bold. Any help would be appreciated. The code is below:

Option Explicit
Private mcolFasteners As Collection

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
'Changes cell B2 value among
'"Royal Sovereign, Sentinel, Hip and Ridge" on double-click.

'Limit the effect to cell B2.
If Target.Address < Range("B2").Address Then
Cancel = False
Exit Sub
End If

On Error GoTo ErrHandler
Dim strBuf As String, v As Variant
'Instatiate and populate a collection
'if not already done.
If mcolFasteners Is Nothing Then
Set mcolFasteners = New Collection
With mcolFasteners
.Add "Royal Sovereign", "Sentinel"
.Add "Hip & Ridge", "Royal Sovereign"
.Add "Sentinel", "Hip & Ridge"
End With
End If

'Get, then clear the current value.
strBuf = LCase(Trim(Target.Text))
Target.Clear

'If it is in our collection, use it as
'an index to the next item in the collection.
For Each v In mcolFasteners
If LCase(CStr(v)) = strBuf Then
Target.Value = mcolFasteners(v)
Exit For
End If
Next v

'If not, just assign the cell one of the values.
If Len(Target.Value) < 1 Then
Target.Value = mcolFasteners(1)
End If

ErrHandler:
Cancel = True

End Sub





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
condionally formatting based on another cells formatting? Derrick Excel Discussion (Misc queries) 2 July 31st 09 08:05 PM
Formatting cells in a column with conditional formatting? shamor Excel Discussion (Misc queries) 8 May 19th 08 10:11 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
expanding custom formatting without removing existing cell formatting? Keith Excel Worksheet Functions 3 December 27th 06 01:54 PM
Decimal Formatting in Windows English vs European Formatting Drummer361 Excel Programming 3 August 7th 06 02:48 PM


All times are GMT +1. The time now is 10:55 PM.

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"