#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mike
 
Posts: n/a
Default functions

I am looking to add data from an opc server into cell A3, everytime data
comes in I want the old data to drop down one.A4, A5, A6 and so on.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ken Johnson
 
Posts: n/a
Default functions

Hi Mike,

this worked for me when ever I entered a value into A3...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$3" Then
Dim rgOldValues As Range
Dim iLastRow As Long
iLastRow = Me.Cells(Range("A:A").Rows.Count, 1) _
..End(xlUp).Row
Application.EnableEvents = False
Select Case iLastRow
Case 1
Case 2
Case 3
Range("A4").Value = Range("A3").Value
Case Else
Set rgOldValues = Me.Range("A4:A" & iLastRow)
rgOldValues.Cut _
Destination:=Me.Range("A5:A" & iLastRow + 1)
Range("A4").Value = Range("A3").Value
End Select
Application.EnableEvents = True
End If
End Sub


Could be a horse of a different colour though when the change is from
an opc server.

To get the code in place...

1. Copy it
2. Right click the worksheet's sheet tab then select "View Code" from
the popup menu.
3. Paste the code into the worksheet's code module that appears.
4. Press Alt + F11 to get back to the worksheet.

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
mikespeck
 
Posts: n/a
Default functions


Everything worked great. I truly appreciate that. Is there something i
could use that would let me do multiple columns. B3, C3, D3, etc?:)


--
mikespeck
------------------------------------------------------------------------
mikespeck's Profile: http://www.excelforum.com/member.php...o&userid=34946
View this thread: http://www.excelforum.com/showthread...hreadid=546673

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ken Johnson
 
Posts: n/a
Default functions

Hi Mike,

try this, which extends the effect from A3 up to G3. If that's not
enough columns then just edit the address "A3:G3" in the first line "If
Not Intersect(Range(Target.Address), Me.Range("A3:G3")) Is Nothing
Then" to suit your needs, eg changing that address to "A3:J3" will give
you 10 columns..

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range(Target.Address), Me.Range("A3:G3")) _
Is Nothing Then
Dim rgOldValues As Range
Dim iLastRow As Long
iLastRow = Me.Cells(Columns(Target.Column).Rows.Count, 1) _
..End(xlUp).Row
Application.EnableEvents = False
Select Case iLastRow
Case 1
Case 2
Case 3
Cells(4, Target.Column).Value = Cells(3, Target.Column).Value
Case Else
Set rgOldValues = Me.Range(Cells(Target.Row + 1, Target.Column), _
Cells(iLastRow, Target.Column))
rgOldValues.Cut _
Destination:=Me.Range(Cells(Target.Row + 2, Target.Column), _
Cells(iLastRow + 1, Target.Column))
Cells(4, Target.Column).Value = Cells(3, Target.Column).Value
End Select
Application.EnableEvents = True
End If
End Sub
Ken Johnson.

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ken Johnson
 
Posts: n/a
Default functions

Hi Mike,

two things..

1. There's a mistake in my last reply, which I have now fixed up.

2. To cover the possibility of the data reaching the bottom of the
sheet I have included a line that clears the bottom-most row of the
target column so that there is room for moving all the old data down
one row....

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range(Target.Address), Me.Range("A3:G3")) _
Is Nothing Then
Me.Cells(Me.Range("A:A").Rows.Count, Target.Column).Clear
Dim rgOldValues As Range
Dim iLastRow As Long
iLastRow = Me.Cells(Columns(Target.Column).Rows.Count, Target.Column) _
..End(xlUp).Row
Application.EnableEvents = False
Select Case iLastRow
Case 1
Case 2
Case 3
Cells(4, Target.Column).Value = Cells(3, Target.Column).Value
Case Else
Set rgOldValues = Me.Range(Cells(Target.Row + 1, Target.Column), _
Cells(iLastRow, Target.Column))
rgOldValues.Cut _
Destination:=Me.Range(Cells(Target.Row + 2, Target.Column), _
Cells(iLastRow + 1, Target.Column))
Cells(4, Target.Column).Value = Cells(3, Target.Column).Value
End Select
Application.EnableEvents = True
End If
End Sub


Ken Johnson



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
mikespeck
 
Posts: n/a
Default functions


Thanks Ken I appreciate all of your help! Everything works great.
Thanks again,
Mike


--
mikespeck
------------------------------------------------------------------------
mikespeck's Profile: http://www.excelforum.com/member.php...o&userid=34946
View this thread: http://www.excelforum.com/showthread...hreadid=546673

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
Can I get Excel to determine the line curve formula without graph. Cadelima Excel Discussion (Misc queries) 8 December 20th 05 09:57 PM
User-defined functions created in Excel 2000 fail in Excel 2003 goodguy Excel Discussion (Misc queries) 1 October 3rd 05 07:04 PM
Database functions should use criteria in formula, as 1-2-3 does 123user Excel Worksheet Functions 8 September 29th 05 08:57 PM
Changing the range of several averaging functions Hellion Excel Discussion (Misc queries) 1 September 17th 05 02:12 PM
Visible rows and functions that work tracy Excel Worksheet Functions 2 August 19th 05 05:25 AM


All times are GMT +1. The time now is 10:53 AM.

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"