Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Updating another sheet using an On Change event

I have two sheets, one which has the latest price of an item and another
which maintains a history of the price per item, I need to be able to update
the historical price on sheet 2 in the correct column when the price is
changed on sheet1.

Example

Sheet1

Item Price
A 10
B 12


Sheet2

Item Jan Feb Mar Apr...
A 8 9 8 10
B 12 11 10 12

The values in sheet2 for April need to be updated by the changes to the
values in sheet1

The column offset is particularly perplexing me!

Anyone got any ideas

Many thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Updating another sheet using an On Change event

right click on the sheet tab of Sheet1 and select view code. Put in code
like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim nMth As Long, sVal As String
Dim rng As Range, rng1 As Range
Dim res As Variant
If Target.Count 1 Then Exit Sub
If Target.Column < 2 Then Exit Sub
nMth = Month(Date)
sVal = Cells(Target.Row, 1)
With Worksheets("sheet2")
Set rng = .Range(.Cells(2, 1), _
.Cells(Rows.Count, 1).End(xlUp))
End With
res = Application.Match(sVal, rng, 0)
If Not IsError(res) Then
Set rng1 = rng(res)
rng1.Offset(0, nMth).Value = Target.Value
End If

End Sub

--
Regards,
Tom Ogilvy

"Steve Barber" wrote in message
...
I have two sheets, one which has the latest price of an item and another
which maintains a history of the price per item, I need to be able to

update
the historical price on sheet 2 in the correct column when the price is
changed on sheet1.

Example

Sheet1

Item Price
A 10
B 12


Sheet2

Item Jan Feb Mar Apr...
A 8 9 8 10
B 12 11 10 12

The values in sheet2 for April need to be updated by the changes to the
values in sheet1

The column offset is particularly perplexing me!

Anyone got any ideas

Many thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Updating another sheet using an On Change event

Works a treat - Thank you very much!!
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
How do I change the Sheet name without updating formulas? [email protected] Excel Discussion (Misc queries) 4 August 15th 08 07:14 PM
Cancel sheet change event NSK Charts and Charting in Excel 1 July 17th 07 08:25 PM
Excel VBA - Add Sheet Change Event at Run Time cidol Excel Programming 6 July 20th 04 09:52 AM
Sheet Name Change Event? Bob L. Excel Programming 0 August 18th 03 10:08 PM
Sheet Name Change Event? Bob Phillips[_5_] Excel Programming 0 August 18th 03 09:57 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"