PC Review


Reply
Thread Tools Rate Thread

Change Cell contents

 
 
=?Utf-8?B?SGFzc2Fu?=
Guest
Posts: n/a
 
      22nd Sep 2007
Hi All,

Is it possible to change the cell value when there is any word exist in that
cell?
e.g.

GPS; Ignition off
TM; Ignition off
ST; Ignition off
Ignition off

when there is Ignition off with anyother word the cell value change to
Ignition off.

Thanks & Regards

Hassan
 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      22nd Sep 2007
Yes, with a change event macro. This is for cell B9, but can be modified for
any range:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("B9"), Target) Is Nothing Then Exit Sub
s = "Ignition off"
v = Target.Value
If InStr(1, v, s) = 0 Then Exit Sub
Application.EnableEvents = False
Target.Value = s
Application.EnableEvents = True
End Sub

Paste this in the worksheet code area, NOT a standard module.
--
Gary''s Student - gsnu200746


"Hassan" wrote:

> Hi All,
>
> Is it possible to change the cell value when there is any word exist in that
> cell?
> e.g.
>
> GPS; Ignition off
> TM; Ignition off
> ST; Ignition off
> Ignition off
>
> when there is Ignition off with anyother word the cell value change to
> Ignition off.
>
> Thanks & Regards
>
> Hassan

 
Reply With Quote
 
=?Utf-8?B?SGFzc2Fu?=
Guest
Posts: n/a
 
      22nd Sep 2007
Hi Gary,

Is it possible to change in active sheet?

Please write in standard module.

"Gary''s Student" wrote:

> Yes, with a change event macro. This is for cell B9, but can be modified for
> any range:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Intersect(Range("B9"), Target) Is Nothing Then Exit Sub
> s = "Ignition off"
> v = Target.Value
> If InStr(1, v, s) = 0 Then Exit Sub
> Application.EnableEvents = False
> Target.Value = s
> Application.EnableEvents = True
> End Sub
>
> Paste this in the worksheet code area, NOT a standard module.
> --
> Gary''s Student - gsnu200746
>
>
> "Hassan" wrote:
>
> > Hi All,
> >
> > Is it possible to change the cell value when there is any word exist in that
> > cell?
> > e.g.
> >
> > GPS; Ignition off
> > TM; Ignition off
> > ST; Ignition off
> > Ignition off
> >
> > when there is Ignition off with anyother word the cell value change to
> > Ignition off.
> >
> > Thanks & Regards
> >
> > Hassan

 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      22nd Sep 2007
To make it work on the active sheet, the macro would have to be installed on
every sheet that the action is required. It is o.k. to make multiple copies
of the code, one for each wroksheet.

I see that it would be good to use a standard module but I don't know how to
do it.
--
Gary''s Student - gsnu200746


"Hassan" wrote:

> Hi Gary,
>
> Is it possible to change in active sheet?
>
> Please write in standard module.
>
> "Gary''s Student" wrote:
>
> > Yes, with a change event macro. This is for cell B9, but can be modified for
> > any range:
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > If Intersect(Range("B9"), Target) Is Nothing Then Exit Sub
> > s = "Ignition off"
> > v = Target.Value
> > If InStr(1, v, s) = 0 Then Exit Sub
> > Application.EnableEvents = False
> > Target.Value = s
> > Application.EnableEvents = True
> > End Sub
> >
> > Paste this in the worksheet code area, NOT a standard module.
> > --
> > Gary''s Student - gsnu200746
> >
> >
> > "Hassan" wrote:
> >
> > > Hi All,
> > >
> > > Is it possible to change the cell value when there is any word exist in that
> > > cell?
> > > e.g.
> > >
> > > GPS; Ignition off
> > > TM; Ignition off
> > > ST; Ignition off
> > > Ignition off
> > >
> > > when there is Ignition off with anyother word the cell value change to
> > > Ignition off.
> > >
> > > Thanks & Regards
> > >
> > > Hassan

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Sep 2007
Another option would be to make it into a workbook_sheetchange event.

This code is placed under the ThisWorkbook module (and the other worksheet
events should be removed).

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Dim s As String
Dim v As Variant

If Intersect(Sh.Range("B9"), Target) Is Nothing Then Exit Sub

s = "Ignition off"
v = Target.Value
If InStr(1, v, s, vbTextCompare) = 0 Then Exit Sub
Application.EnableEvents = False
Target.Value = s
Application.EnableEvents = True
End Sub

If there are sheets that should be ignored, then that could be added to the
code.



Gary''s Student wrote:
>
> To make it work on the active sheet, the macro would have to be installed on
> every sheet that the action is required. It is o.k. to make multiple copies
> of the code, one for each wroksheet.
>
> I see that it would be good to use a standard module but I don't know how to
> do it.
> --
> Gary''s Student - gsnu200746
>
> "Hassan" wrote:
>
> > Hi Gary,
> >
> > Is it possible to change in active sheet?
> >
> > Please write in standard module.
> >
> > "Gary''s Student" wrote:
> >
> > > Yes, with a change event macro. This is for cell B9, but can be modified for
> > > any range:
> > >
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > If Intersect(Range("B9"), Target) Is Nothing Then Exit Sub
> > > s = "Ignition off"
> > > v = Target.Value
> > > If InStr(1, v, s) = 0 Then Exit Sub
> > > Application.EnableEvents = False
> > > Target.Value = s
> > > Application.EnableEvents = True
> > > End Sub
> > >
> > > Paste this in the worksheet code area, NOT a standard module.
> > > --
> > > Gary''s Student - gsnu200746
> > >
> > >
> > > "Hassan" wrote:
> > >
> > > > Hi All,
> > > >
> > > > Is it possible to change the cell value when there is any word exist in that
> > > > cell?
> > > > e.g.
> > > >
> > > > GPS; Ignition off
> > > > TM; Ignition off
> > > > ST; Ignition off
> > > > Ignition off
> > > >
> > > > when there is Ignition off with anyother word the cell value change to
> > > > Ignition off.
> > > >
> > > > Thanks & Regards
> > > >
> > > > Hassan


--

Dave Peterson
 
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
change cell contents when pull down menu choices change jb21 Microsoft Excel Worksheet Functions 3 21st Nov 2008 10:34 PM
Change contents of a cell based on cell contents. =?Utf-8?B?TWFobmlhbg==?= Microsoft Excel Programming 3 4th May 2007 10:49 PM
change cell shading whenever contents different from previous cell =?Utf-8?B?em9vZXloYWxsbmU=?= Microsoft Excel Misc 3 6th Jun 2005 09:59 PM
Change Cell Color dependent on Cell Contents =?Utf-8?B?QmlsbA==?= Microsoft Excel Programming 4 15th Mar 2005 04:33 PM
Please help! Macro to change cell contents based on cell to the left Jennifer Microsoft Excel Programming 7 4th Mar 2004 01:06 AM


Features
 

Advertising
 

Newsgroups
 


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