PC Review


Reply
Thread Tools Rate Thread

apply cell change event to single column - WorksheetChange Event

 
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      3rd May 2008
dumbest question that will be posted all day, but here goes anyway.
How do I change the following macro so that it only applies to one
column instead of two? I don't know how to properly modify
Range(Cells(Target.Row, 15), Cells(Target.Row, 16)) to just one of
those columns. Deleting the second "range" gives me a run-time
error. Maybe I should be using something all together different
anyway. When the user enters a value into Column 14, I want the word
"Subfile" to appear in Column 15; however, if the user deletes the
text in Column 14, I want "Subfile" removed/deleted.

Any and all help is always appreciated.

Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

If Target.Column = 14 And Target.Value <> "" Then
Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value =
"Subfile"
End If

If Target.Column = 14 And Target.Value = "" Then
Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value = ""
End If

Application.EnableEvents = True
End Sub
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      3rd May 2008
On 3 Maj, 11:52, MiataDia...@gmail.com wrote:
> dumbest question that will be posted all day, but here goes anyway.
> How do I change the following macro so that it only applies to one
> column instead of two? *I don't know how to properly modify
> Range(Cells(Target.Row, 15), Cells(Target.Row, 16)) to just one of
> those columns. *Deleting the second "range" gives me a run-time
> error. *Maybe I should be using something all together different
> anyway. *When the user enters a value into Column 14, I want the word
> "Subfile" to appear in Column 15; however, if the user deletes the
> text in Column 14, I want "Subfile" removed/deleted.
>
> Any and all help is always appreciated.
>
> Sub Worksheet_Change(ByVal Target As Range)
> Application.EnableEvents = False
>
> If Target.Column = 14 And Target.Value <> "" Then
> * * *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value =
> "Subfile"
> End If
>
> If Target.Column = 14 And Target.Value = "" Then
> *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value = ""
> *End If
>
> Application.EnableEvents = True
> End Sub


Hi
Try this:

Range(Cells(Target.Row,15)).Value=""

Regards,
Per
 
Reply With Quote
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      3rd May 2008
On May 3, 6:41*am, Per Jessen <perjesse...@hotmail.com> wrote:
> On 3 Maj, 11:52, MiataDia...@gmail.com wrote:
>
>
>
>
>
> > dumbest question that will be posted all day, but here goes anyway.
> > How do I change the following macro so that it only applies to one
> > column instead of two? *I don't know how to properly modify
> > Range(Cells(Target.Row, 15), Cells(Target.Row, 16)) to just one of
> > those columns. *Deleting the second "range" gives me a run-time
> > error. *Maybe I should be using something all together different
> > anyway. *When the user enters a value into Column 14, I want the word
> > "Subfile" to appear in Column 15; however, if the user deletes the
> > text in Column 14, I want "Subfile" removed/deleted.

>
> > Any and all help is always appreciated.

>
> > Sub Worksheet_Change(ByVal Target As Range)
> > Application.EnableEvents = False

>
> > If Target.Column = 14 And Target.Value <> "" Then
> > * * *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value =
> > "Subfile"
> > End If

>
> > If Target.Column = 14 And Target.Value = "" Then
> > *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value = ""
> > *End If

>
> > Application.EnableEvents = True
> > End Sub

>
> Hi
> Try this:
>
> Range(Cells(Target.Row,15)).Value=""
>
> Regards,
> Per- Hide quoted text -
>
> - Show quoted text -


fantastic! what did I ever do before Google??? One additional
question that I should have asked before. If 14 contains a comma or
an ampersand, then subfile should be subfiles.
 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      3rd May 2008
Try this:

Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set r = Range("N:N")
If Intersect(t, r) Is Nothing Then Exit Sub
Application.EnableEvents = False
v = t.Value
If v = "" Then
t.Offset(0, 1).Value = ""
Else
If v = "," Or v = "&" Then
t.Offset(0, 1).Value = "Subfiles"
Else
t.Offset(0, 1).Value = "Subfile"
End If
End If
Application.EnableEvents = True
End Sub

--
Gary''s Student - gsnu2007h


"(E-Mail Removed)" wrote:

> On May 3, 6:41 am, Per Jessen <perjesse...@hotmail.com> wrote:
> > On 3 Maj, 11:52, MiataDia...@gmail.com wrote:
> >
> >
> >
> >
> >
> > > dumbest question that will be posted all day, but here goes anyway.
> > > How do I change the following macro so that it only applies to one
> > > column instead of two? I don't know how to properly modify
> > > Range(Cells(Target.Row, 15), Cells(Target.Row, 16)) to just one of
> > > those columns. Deleting the second "range" gives me a run-time
> > > error. Maybe I should be using something all together different
> > > anyway. When the user enters a value into Column 14, I want the word
> > > "Subfile" to appear in Column 15; however, if the user deletes the
> > > text in Column 14, I want "Subfile" removed/deleted.

> >
> > > Any and all help is always appreciated.

> >
> > > Sub Worksheet_Change(ByVal Target As Range)
> > > Application.EnableEvents = False

> >
> > > If Target.Column = 14 And Target.Value <> "" Then
> > > Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value =
> > > "Subfile"
> > > End If

> >
> > > If Target.Column = 14 And Target.Value = "" Then
> > > Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value = ""
> > > End If

> >
> > > Application.EnableEvents = True
> > > End Sub

> >
> > Hi
> > Try this:
> >
> > Range(Cells(Target.Row,15)).Value=""
> >
> > Regards,
> > Per- Hide quoted text -
> >
> > - Show quoted text -

>
> fantastic! what did I ever do before Google??? One additional
> question that I should have asked before. If 14 contains a comma or
> an ampersand, then subfile should be subfiles.
>

 
Reply With Quote
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      3rd May 2008
On May 3, 8:39*am, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> Try this:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Set t = Target
> Set r = Range("N:N")
> If Intersect(t, r) Is Nothing Then Exit Sub
> Application.EnableEvents = False
> v = t.Value
> If v = "" Then
> * * t.Offset(0, 1).Value = ""
> Else
> * * If v = "," Or v = "&" Then
> * * * * t.Offset(0, 1).Value = "Subfiles"
> * * Else
> * * * * t.Offset(0, 1).Value = "Subfile"
> * * End If
> End If
> Application.EnableEvents = True
> End Sub
>
> --
> Gary''s Student - gsnu2007h
>
>
>
> "MiataDia...@gmail.com" wrote:
> > On May 3, 6:41 am, Per Jessen <perjesse...@hotmail.com> wrote:
> > > On 3 Maj, 11:52, MiataDia...@gmail.com wrote:

>
> > > > dumbest question that will be posted all day, but here goes anyway.
> > > > How do I change the following macro so that it only applies to one
> > > > column instead of two? *I don't know how to properly modify
> > > > Range(Cells(Target.Row, 15), Cells(Target.Row, 16)) to just one of
> > > > those columns. *Deleting the second "range" gives me a run-time
> > > > error. *Maybe I should be using something all together different
> > > > anyway. *When the user enters a value into Column 14, I want the word
> > > > "Subfile" to appear in Column 15; however, if the user deletes the
> > > > text in Column 14, I want "Subfile" removed/deleted.

>
> > > > Any and all help is always appreciated.

>
> > > > Sub Worksheet_Change(ByVal Target As Range)
> > > > Application.EnableEvents = False

>
> > > > If Target.Column = 14 And Target.Value <> "" Then
> > > > * * *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value=
> > > > "Subfile"
> > > > End If

>
> > > > If Target.Column = 14 And Target.Value = "" Then
> > > > *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value = ""
> > > > *End If

>
> > > > Application.EnableEvents = True
> > > > End Sub

>
> > > Hi
> > > Try this:

>
> > > Range(Cells(Target.Row,15)).Value=""

>
> > > Regards,
> > > Per- Hide quoted text -

>
> > > - Show quoted text -

>
> > fantastic! *what did I ever do before Google??? *One additional
> > question that I should have asked before. *If 14 contains a comma or
> > an ampersand, then subfile should be subfiles.- Hide quoted text -

>
> - Show quoted text -


Gary's student, you're not only a great person, but you're officially
my hero today.
 
Reply With Quote
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      4th May 2008
On May 3, 1:52*pm, MiataDia...@gmail.com wrote:
> On May 3, 8:39*am, Gary''s Student
>
>
>
>
>
> <GarysStud...@discussions.microsoft.com> wrote:
> > Try this:

>
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > Set t = Target
> > Set r = Range("N:N")
> >IfIntersect(t, r) Is Nothing Then Exit Sub
> > Application.EnableEvents = False
> > v = t.Value
> >Ifv = "" Then
> > * * t.Offset(0, 1).Value = ""
> > Else
> > * *Ifv = "," Or v = "&" Then
> > * * * * t.Offset(0, 1).Value = "Subfiles"
> > * * Else
> > * * * * t.Offset(0, 1).Value = "Subfile"
> > * * EndIf
> > EndIf
> > Application.EnableEvents = True
> > End Sub

>
> > --
> > Gary''s Student - gsnu2007h

>
> > "MiataDia...@gmail.com" wrote:
> > > On May 3, 6:41 am, Per Jessen <perjesse...@hotmail.com> wrote:
> > > > On 3 Maj, 11:52, MiataDia...@gmail.com wrote:

>
> > > > > dumbest question that will be posted all day, but here goes anyway..
> > > > > How do I change the following macro so that it only applies to one
> > > > > column instead of two? *I don't know how to properly modify
> > > > > Range(Cells(Target.Row, 15), Cells(Target.Row, 16)) to just one of
> > > > > those columns. *Deleting the second "range" gives me a run-time
> > > > > error. *Maybe I should be using something all together different
> > > > > anyway. *When the user enters a value into Column 14, I want theword
> > > > > "Subfile" to appear in Column 15; however,ifthe user deletes the
> > > > > text in Column 14, I want "Subfile" removed/deleted.

>
> > > > > Any and all help is always appreciated.

>
> > > > > Sub Worksheet_Change(ByVal Target As Range)
> > > > > Application.EnableEvents = False

>
> > > > >IfTarget.Column = 14 And Target.Value <> "" Then
> > > > > * * *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value =
> > > > > "Subfile"
> > > > > EndIf

>
> > > > >IfTarget.Column = 14 And Target.Value = "" Then
> > > > > *Range(Cells(Target.Row, 15), Cells(Target.Row, 16)).Value = ""
> > > > > *EndIf

>
> > > > > Application.EnableEvents = True
> > > > > End Sub

>
> > > > Hi
> > > > Try this:

>
> > > > Range(Cells(Target.Row,15)).Value=""

>
> > > > Regards,
> > > > Per- Hide quoted text -

>
> > > > - Show quoted text -

>
> > > fantastic! *what did I ever do before Google??? *One additional
> > > question that I should have asked before. *If14containsacommaor
> > > an ampersand, then subfile should be subfiles.- Hide quoted text -

>
> > - Show quoted text -

>
> Gary's student, you're not only a great person, but you're officially
> my hero today.- Hide quoted text -
>
> - Show quoted text -


Well, I thought I could figure out the last part from here. What you
gave me works perfectly for subfiles if "N" contains ONLY a comma or
ONLY an ampersand. But the data for that cell will contain text like
"CLN1237, BNK1535 & GEA1981" or "CLN1237 & BNK1535". How do I insert
the "like" operator in your code the way I would use it for a query in
Access? I never thought I would ever say that making things happen in
Access is easier than Excel.

Thanks again for your help, I truly appreciate your time and
assistance.

 
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
single occurring event gets changed to reoccurring event =?Utf-8?B?SkdU?= Microsoft Outlook Discussion 4 28th May 2007 06:16 AM
Change event on single cell fires many times =?Utf-8?B?WFA=?= Microsoft Excel Programming 3 6th Nov 2006 10:16 PM
Worksheet change event-single column =?Utf-8?B?amFzbWluZXN5?= Microsoft Excel Programming 2 17th Jul 2006 06:27 PM
Datagrid cell change event? Where to find event. Roger Microsoft VB .NET 4 29th Mar 2005 09:45 PM
Multiple Event Handlers for a Single Event - Newbie Question. Andy Cooper Microsoft VB .NET 8 2nd Jan 2004 04:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 PM.