Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 39
Default help with inputting code

hi there,
i have some code (below) that takes the value of cell U17 every time it
changes and then lists it in a column on the 'graphs' sheet for charting
purposes. i would like to duplicate this code for another cell W25 having it
form a list on the 'graphs' sheet in column K, when i copied the code below
then pasted it into VB and amended the values it came up with a compile error
:(
it must be something simple that i'm doing wrong, any ideas?


Private Sub Worksheet_Calculate()
Dim Dest As Range
With Sheets("graphs")
Set Dest = .Range("A" & Rows.Count).End(xlUp)
If Range("U17") < Dest Then _
Dest.Offset(1) = Range("U17")
End With
End Sub

--
thanks
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2,203
Default help with inputting code

Each worksheet can only have one event handler for each event. In your case,
you want to test for changes in 2 different cells, U17 and W25, so you have
to handle both in a single routine. And I don't think the Calculate() event
is a good one for this anyhow.

Make a copy of your workbook to test with and try the following in it.

First, delete the existing code you have. Replace it with this code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Dest As Range
Dim destColumn As String

If Target.Address < "$U$17" And _
Target.Address < "$W$25" Then
Exit Sub ' neither cell changed
End If
Select Case Target.Address
Case Is = "$U$17"
destColumn = "A"
Case Is = "$W$25"
destColumn = "K"
End Select
With Sheets("Graphs")
Set Dest = .Range(destColumn & Rows.Count).End(xlUp)
If Target.Value < Dest.Value Then
Dest.Offset(0, 1) = Target
End If
End With
End Sub

That code should be placed into the code module for the sheet with U17 and
W25 on it. To check to see if it is in the right place when you're finished,
close the VB Editor and right-click on that sheet's name tab and choose [View
Code] and you should see it there.

"Morgan" wrote:

hi there,
i have some code (below) that takes the value of cell U17 every time it
changes and then lists it in a column on the 'graphs' sheet for charting
purposes. i would like to duplicate this code for another cell W25 having it
form a list on the 'graphs' sheet in column K, when i copied the code below
then pasted it into VB and amended the values it came up with a compile error
:(
it must be something simple that i'm doing wrong, any ideas?


Private Sub Worksheet_Calculate()
Dim Dest As Range
With Sheets("graphs")
Set Dest = .Range("A" & Rows.Count).End(xlUp)
If Range("U17") < Dest Then _
Dest.Offset(1) = Range("U17")
End With
End Sub

--
thanks

  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 39
Default help with inputting code

thanks for your efforts, it seems to kind of work, but as the values for the
two cells change i needed them to be inputted separately into their
respective columns on the 'graphs' sheet, thereby forming a list down the
page of each values that appears in those cells. Currently only the current
value of those two cells is being displayed on the graphs sheet,

any ideas?


"JLatham" wrote:

Each worksheet can only have one event handler for each event. In your case,
you want to test for changes in 2 different cells, U17 and W25, so you have
to handle both in a single routine. And I don't think the Calculate() event
is a good one for this anyhow.

Make a copy of your workbook to test with and try the following in it.

First, delete the existing code you have. Replace it with this code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Dest As Range
Dim destColumn As String

If Target.Address < "$U$17" And _
Target.Address < "$W$25" Then
Exit Sub ' neither cell changed
End If
Select Case Target.Address
Case Is = "$U$17"
destColumn = "A"
Case Is = "$W$25"
destColumn = "K"
End Select
With Sheets("Graphs")
Set Dest = .Range(destColumn & Rows.Count).End(xlUp)
If Target.Value < Dest.Value Then
Dest.Offset(0, 1) = Target
End If
End With
End Sub

That code should be placed into the code module for the sheet with U17 and
W25 on it. To check to see if it is in the right place when you're finished,
close the VB Editor and right-click on that sheet's name tab and choose [View
Code] and you should see it there.

"Morgan" wrote:

hi there,
i have some code (below) that takes the value of cell U17 every time it
changes and then lists it in a column on the 'graphs' sheet for charting
purposes. i would like to duplicate this code for another cell W25 having it
form a list on the 'graphs' sheet in column K, when i copied the code below
then pasted it into VB and amended the values it came up with a compile error
:(
it must be something simple that i'm doing wrong, any ideas?


Private Sub Worksheet_Calculate()
Dim Dest As Range
With Sheets("graphs")
Set Dest = .Range("A" & Rows.Count).End(xlUp)
If Range("U17") < Dest Then _
Dest.Offset(1) = Range("U17")
End With
End Sub

--
thanks

  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2,203
Default help with inputting code

It should work. I'll make the same offer that has been made elsewhe send
a copy to me as an attachment to an email and I'll see what I can do with it.
Send the email to (remove spaces) HelpFrom @ JLatham Site. com


"Morgan" wrote:

thanks for your efforts, it seems to kind of work, but as the values for the
two cells change i needed them to be inputted separately into their
respective columns on the 'graphs' sheet, thereby forming a list down the
page of each values that appears in those cells. Currently only the current
value of those two cells is being displayed on the graphs sheet,

any ideas?


"JLatham" wrote:

Each worksheet can only have one event handler for each event. In your case,
you want to test for changes in 2 different cells, U17 and W25, so you have
to handle both in a single routine. And I don't think the Calculate() event
is a good one for this anyhow.

Make a copy of your workbook to test with and try the following in it.

First, delete the existing code you have. Replace it with this code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Dest As Range
Dim destColumn As String

If Target.Address < "$U$17" And _
Target.Address < "$W$25" Then
Exit Sub ' neither cell changed
End If
Select Case Target.Address
Case Is = "$U$17"
destColumn = "A"
Case Is = "$W$25"
destColumn = "K"
End Select
With Sheets("Graphs")
Set Dest = .Range(destColumn & Rows.Count).End(xlUp)
If Target.Value < Dest.Value Then
Dest.Offset(0, 1) = Target
End If
End With
End Sub

That code should be placed into the code module for the sheet with U17 and
W25 on it. To check to see if it is in the right place when you're finished,
close the VB Editor and right-click on that sheet's name tab and choose [View
Code] and you should see it there.

"Morgan" wrote:

hi there,
i have some code (below) that takes the value of cell U17 every time it
changes and then lists it in a column on the 'graphs' sheet for charting
purposes. i would like to duplicate this code for another cell W25 having it
form a list on the 'graphs' sheet in column K, when i copied the code below
then pasted it into VB and amended the values it came up with a compile error
:(
it must be something simple that i'm doing wrong, any ideas?


Private Sub Worksheet_Calculate()
Dim Dest As Range
With Sheets("graphs")
Set Dest = .Range("A" & Rows.Count).End(xlUp)
If Range("U17") < Dest Then _
Dest.Offset(1) = Range("U17")
End With
End Sub

--
thanks

Reply
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
Inputting criteria into a macro/vb code Marie Bayes Excel Discussion (Misc queries) 9 December 9th 07 12:17 PM
Inputting date as dd/mm not mm/dd MichaelH Excel Discussion (Misc queries) 2 May 26th 07 11:42 AM
Inputting a length of time? Link New Users to Excel 12 May 22nd 07 11:49 AM
inputting data Shanor Excel Discussion (Misc queries) 0 June 15th 06 10:50 AM
Inputting Source Data - help please foredis Charts and Charting in Excel 1 June 22nd 05 02:36 PM


All times are GMT +1. The time now is 10:00 PM.

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"