LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
Packman
 
Posts: n/a
Default Changing an active cell format in VBA

Hi,

I'm trying to use VBA to change the date format of a cell when a
preceeding cell is changed. I am using data validation so it is a list
box, and the contents of the list box change depending on if the
variable "annual" or "monthly" is selected:

=IF($N$3="Annual",DATE_RANGE_ANN,DATE_RANGE_MON)

Here is the code behind the sheet I am trying to run when cell(N3) is
selected:

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$N$3" Then

If Target.Value = "Annual" Then

Target.Offset(0, -1).NumberFormat = "yyyy"

Else

Target.Offset(0, -1).NumberFormat = "mmmm-yyyy"

End If

End If

End Sub


I should point out that both cells N3 and N4 are merged cells. I was
not sure if that would create a problem. Any help is greatly
appreciated...thanks.

 
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
cell format changing when when using search and replace. Excel Discussion (Misc queries) 0 January 6th 06 02:41 AM
cell format changing when when using search and replace. Excel Discussion (Misc queries) 0 January 6th 06 02:41 AM
Changing cell format - for example text to numeric sjrku Excel Discussion (Misc queries) 3 December 30th 05 10:40 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
difficulty changing cell format samsmimi Excel Worksheet Functions 4 April 1st 05 12:25 AM


All times are GMT +1. The time now is 11:45 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"