PC Review


Reply
Thread Tools Rate Thread

Code to add Range Value produces nothing

 
 
ssGuru
Guest
Posts: n/a
 
      17th Aug 2007
I want to add a value in col 26 in the current row IF a change occurs
in Column 3 of that row.
I have a cell with a named range "RptCreator", in the worksheet
"InstructionPrice"
Any ideas why this code DOES NOT add any value to Col 26? or anywhere
else.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Pn As String

If Target.Column = 3 Then
r = Target.Row
c = Target.Column
Pn = Sheets("InstructionPrice").Range("RptCreator").Value
If Cells(r, c) = Empty Then
Cells(r, 26) = Pn
End If
End If
End Sub

Thanks, Dennis

 
Reply With Quote
 
 
 
 
George Nicholson
Guest
Posts: n/a
 
      17th Aug 2007
1) As written, Cells(r,c) = Target (the cell just changed). You know that,
right? (Then why not just use Target?)

2)
> If Cells(r, c) = Empty Then

Column 26 should have RptCreator's value placed in it ONLY if you have just
*cleared* Target so that it is now Empty. It will not react to any other
change. Is that not what you are seeing?

HTH,


"ssGuru" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I want to add a value in col 26 in the current row IF a change occurs
> in Column 3 of that row.
> I have a cell with a named range "RptCreator", in the worksheet
> "InstructionPrice"
> Any ideas why this code DOES NOT add any value to Col 26? or anywhere
> else.
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim Pn As String
>
> If Target.Column = 3 Then
> r = Target.Row
> c = Target.Column
> Pn = Sheets("InstructionPrice").Range("RptCreator").Value
> If Cells(r, c) = Empty Then
> Cells(r, 26) = Pn
> End If
> End If
> End Sub
>
> Thanks, Dennis
>



 
Reply With Quote
 
Trevor Shuttleworth
Guest
Posts: n/a
 
      17th Aug 2007
Dennis

If Cells(r, c) = Empty Then

Cells(r,c) is the target cell ... you pick up the values from the target row
and column. So the only way the above statement will be true is if you
delete the contents of the target cell.

You should also disable events before changing the cell as you'll loop
through the Change event again:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
Dim c As Long
Dim Pn As String

If Target.Column = 3 Then
r = Target.Row
c = Target.Column
Pn = Sheets("InstructionPrice").Range("RptCreator").Value
If Cells(r, c) = Empty Then
Application.EnableEvents = False
Cells(r, 26) = Pn
Application.EnableEvents = True
End If
End If
End Sub

Try deleting something in column C ... you'll get a value put in column Z

Regards

Trevor


"ssGuru" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I want to add a value in col 26 in the current row IF a change occurs
> in Column 3 of that row.
> I have a cell with a named range "RptCreator", in the worksheet
> "InstructionPrice"
> Any ideas why this code DOES NOT add any value to Col 26? or anywhere
> else.
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim Pn As String
>
> If Target.Column = 3 Then
> r = Target.Row
> c = Target.Column
> Pn = Sheets("InstructionPrice").Range("RptCreator").Value
> If Cells(r, c) = Empty Then
> Cells(r, 26) = Pn
> End If
> End If
> End Sub
>
> Thanks, Dennis
>



 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      17th Aug 2007
Is the Target cell empty?

"ssGuru" wrote:

> I want to add a value in col 26 in the current row IF a change occurs
> in Column 3 of that row.
> I have a cell with a named range "RptCreator", in the worksheet
> "InstructionPrice"
> Any ideas why this code DOES NOT add any value to Col 26? or anywhere
> else.
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim Pn As String
>
> If Target.Column = 3 Then
> r = Target.Row
> c = Target.Column
> Pn = Sheets("InstructionPrice").Range("RptCreator").Value
> If Cells(r, c) = Empty Then
> Cells(r, 26) = Pn
> End If
> End If
> End Sub
>
> Thanks, Dennis
>
>

 
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
I want a AnimationExtender to run only once but this code produces a complier error Cal Who Microsoft ASP .NET 1 26th Jun 2010 05:32 PM
Word produces some strange characters - can I find out ascii code forthem? FOREVER_NEWBIE Microsoft Word New Users 1 1st Feb 2010 06:50 PM
Identical code produces different output tonyjeffs2@googlemail.com Microsoft VC .NET 8 7th Dec 2007 05:43 AM
code produces compiler error, consistently. can i help more? Zytan Microsoft C# .NET 4 3rd Mar 2007 04:07 AM
BUG VC7.1: well-formed code produces obscure error message Maxim Yegorushkin Microsoft VC .NET 3 4th Jun 2004 12:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:11 PM.