PC Review


Reply
Thread Tools Rate Thread

change cell value by code

 
 
Jock
Guest
Posts: n/a
 
      2nd Mar 2010
I am trying to get the text value in cell D5 to alternate from "show dates"
to "hide dates" depending whether cols A-C (where the dates are) are visible
or not using the following:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
'right clicking D5 will show/hide columns A-C (date, time and user name))
If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
Columns("A:C").EntireColumn.Hidden = Not
Columns("A:C").EntireColumn.Hidden
==>Target.Value = "hide dates": Target.Value = "show dates"<== this
bit pls!
Cancel = True
End If

I'm a bit stuck. Thanks

--
Traa Dy Liooar

Jock
 
Reply With Quote
 
 
 
 
Stefi
Guest
Posts: n/a
 
      2nd Mar 2010
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)
If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
If Columns("A:C").EntireColumn.Hidden = True Then
Columns("A:C").EntireColumn.Hidden = False
Target.Value = "show dates"
Else
Columns("A:C").EntireColumn.Hidden = True
Target.Value = "hide dates"
End If
End If
Cancel = True
End Sub


--
Regards!
Stefi



„Jock” ezt *rta:

> I am trying to get the text value in cell D5 to alternate from "show dates"
> to "hide dates" depending whether cols A-C (where the dates are) are visible
> or not using the following:
>
> Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> Boolean)
> 'right clicking D5 will show/hide columns A-C (date, time and user name))
> If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> Columns("A:C").EntireColumn.Hidden = Not
> Columns("A:C").EntireColumn.Hidden
> ==>Target.Value = "hide dates": Target.Value = "show dates"<== this
> bit pls!
> Cancel = True
> End If
>
> I'm a bit stuck. Thanks
>
> --
> Traa Dy Liooar
>
> Jock

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Mar 2010
Your code worked ok for me (after I fixed the line wrap).

What problem are you having?

Maybe you're not rightclicking on D5 (since it moves when A:C is shown/hidden).

Jock wrote:
>
> I am trying to get the text value in cell D5 to alternate from "show dates"
> to "hide dates" depending whether cols A-C (where the dates are) are visible
> or not using the following:
>
> Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> Boolean)
> 'right clicking D5 will show/hide columns A-C (date, time and user name))
> If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> Columns("A:C").EntireColumn.Hidden = Not
> Columns("A:C").EntireColumn.Hidden
> ==>Target.Value = "hide dates": Target.Value = "show dates"<== this
> bit pls!
> Cancel = True
> End If
>
> I'm a bit stuck. Thanks
>
> --
> Traa Dy Liooar
>
> Jock


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      2nd Mar 2010
Oops. I missed the part about how you wanted the text to alternate.

Sorry.

Dave Peterson wrote:
>
> Your code worked ok for me (after I fixed the line wrap).
>
> What problem are you having?
>
> Maybe you're not rightclicking on D5 (since it moves when A:C is shown/hidden).
>
> Jock wrote:
> >
> > I am trying to get the text value in cell D5 to alternate from "show dates"
> > to "hide dates" depending whether cols A-C (where the dates are) are visible
> > or not using the following:
> >
> > Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> > Boolean)
> > 'right clicking D5 will show/hide columns A-C (date, time and user name))
> > If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> > Columns("A:C").EntireColumn.Hidden = Not
> > Columns("A:C").EntireColumn.Hidden
> > ==>Target.Value = "hide dates": Target.Value = "show dates"<== this
> > bit pls!
> > Cancel = True
> > End If
> >
> > I'm a bit stuck. Thanks
> >
> > --
> > Traa Dy Liooar
> >
> > Jock

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Jock
Guest
Posts: n/a
 
      2nd Mar 2010
Works a treat, thanks.
--
Traa Dy Liooar

Jock


"Stefi" wrote:

> Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> Boolean)
> If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> If Columns("A:C").EntireColumn.Hidden = True Then
> Columns("A:C").EntireColumn.Hidden = False
> Target.Value = "show dates"
> Else
> Columns("A:C").EntireColumn.Hidden = True
> Target.Value = "hide dates"
> End If
> End If
> Cancel = True
> End Sub
>
>
> --
> Regards!
> Stefi
>
>
>
> „Jock” ezt *rta:
>
> > I am trying to get the text value in cell D5 to alternate from "show dates"
> > to "hide dates" depending whether cols A-C (where the dates are) are visible
> > or not using the following:
> >
> > Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> > Boolean)
> > 'right clicking D5 will show/hide columns A-C (date, time and user name))
> > If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> > Columns("A:C").EntireColumn.Hidden = Not
> > Columns("A:C").EntireColumn.Hidden
> > ==>Target.Value = "hide dates": Target.Value = "show dates"<== this
> > bit pls!
> > Cancel = True
> > End If
> >
> > I'm a bit stuck. Thanks
> >
> > --
> > Traa Dy Liooar
> >
> > Jock

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      2nd Mar 2010
Here is another way to write your code...

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
If Target.Address(0, 0) = "D5" Then
With Columns("A:C").EntireColumn
.Hidden = Not .Hidden
Target.Value = IIf(.Hidden, "show", "hide") & " dates"
End With
End If
Cancel = True
End Sub

--
Rick (MVP - Excel)


"Stefi" <(E-Mail Removed)> wrote in message
news:11EECC1D-3E7A-45DA-B739-(E-Mail Removed)...
> Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> Boolean)
> If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> If Columns("A:C").EntireColumn.Hidden = True Then
> Columns("A:C").EntireColumn.Hidden = False
> Target.Value = "show dates"
> Else
> Columns("A:C").EntireColumn.Hidden = True
> Target.Value = "hide dates"
> End If
> End If
> Cancel = True
> End Sub
>
>
> --
> Regards!
> Stefi
>
>
>
> „Jock” ezt *rta:
>
>> I am trying to get the text value in cell D5 to alternate from "show
>> dates"
>> to "hide dates" depending whether cols A-C (where the dates are) are
>> visible
>> or not using the following:
>>
>> Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
>> Boolean)
>> 'right clicking D5 will show/hide columns A-C (date, time and user
>> name))
>> If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
>> Columns("A:C").EntireColumn.Hidden = Not
>> Columns("A:C").EntireColumn.Hidden
>> ==>Target.Value = "hide dates": Target.Value = "show dates"<== this
>> bit pls!
>> Cancel = True
>> End If
>>
>> I'm a bit stuck. Thanks
>>
>> --
>> Traa Dy Liooar
>>
>> Jock


 
Reply With Quote
 
Stefi
Guest
Posts: n/a
 
      3rd Mar 2010
You are welcome! Thanks for the feedback!
--
Regards!
Stefi



„Jock” ezt *rta:

> Works a treat, thanks.
> --
> Traa Dy Liooar
>
> Jock
>
>
> "Stefi" wrote:
>
> > Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> > Boolean)
> > If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> > If Columns("A:C").EntireColumn.Hidden = True Then
> > Columns("A:C").EntireColumn.Hidden = False
> > Target.Value = "show dates"
> > Else
> > Columns("A:C").EntireColumn.Hidden = True
> > Target.Value = "hide dates"
> > End If
> > End If
> > Cancel = True
> > End Sub
> >
> >
> > --
> > Regards!
> > Stefi
> >
> >
> >
> > „Jock” ezt *rta:
> >
> > > I am trying to get the text value in cell D5 to alternate from "show dates"
> > > to "hide dates" depending whether cols A-C (where the dates are) are visible
> > > or not using the following:
> > >
> > > Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
> > > Boolean)
> > > 'right clicking D5 will show/hide columns A-C (date, time and user name))
> > > If Not Application.Intersect(Target, Range("D5")) Is Nothing Then
> > > Columns("A:C").EntireColumn.Hidden = Not
> > > Columns("A:C").EntireColumn.Hidden
> > > ==>Target.Value = "hide dates": Target.Value = "show dates"<== this
> > > bit pls!
> > > Cancel = True
> > > End If
> > >
> > > I'm a bit stuck. Thanks
> > >
> > > --
> > > Traa Dy Liooar
> > >
> > > Jock

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Allow VBA code to change a locked cell?? Paul Kraemer Microsoft Excel Programming 2 5th Feb 2010 12:29 PM
Re: How to Run VBA Code on cell or range change Bob Phillips Microsoft Excel Programming 2 10th Dec 2006 06:50 PM
Re: How to Run VBA Code on cell or range change Dave Peterson Microsoft Excel Programming 0 8th Dec 2006 12:05 AM
code for cell change not working Pal Microsoft Excel Programming 6 8th Mar 2004 12:51 AM
run code after cell contents change Brian Microsoft Excel Programming 0 5th Sep 2003 08:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:18 AM.