A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

data entry from two cells across worksheets



 
 
Thread Tools Display Modes
  #1  
Old March 25th, 2005, 06:58 PM
sp-googling
external usenet poster
 
Posts: n/a
Default data entry from two cells across worksheets

I'm wanting to have cells take the value of the last one updated across
worksheets. I've found the code that accomplishs this within one
worksheet, but not across two. Could anyone make ammendments to the
following code for me?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
Range("A1").Value = Range("A2").Value
ElseIf Target.Address = "$A$1" Then
Range("A2").Value = Range("A1").Value
End If
End Sub

Thanks greatly
Steve

  #2  
Old March 25th, 2005, 07:13 PM
Ramakrishnan Rajamani
external usenet poster
 
Posts: n/a
Default

Try this. Might work

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
Range("A1").Value = Range("A2").Value
ElseIf Target.Address = "$A$1" Then
Range("A2").Value = Range("A1").Value
End If
Sheet2.Range("A1").Value = Sheet1.Range("A1").Value
Sheet2.Range("A2").Value = Sheet1.Range("A2").Value
End Sub

Similarly for other sheets as well


"sp-googling" wrote:

I'm wanting to have cells take the value of the last one updated across
worksheets. I've found the code that accomplishs this within one
worksheet, but not across two. Could anyone make ammendments to the
following code for me?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$2" Then
Range("A1").Value = Range("A2").Value
ElseIf Target.Address = "$A$1" Then
Range("A2").Value = Range("A1").Value
End If
End Sub

Thanks greatly
Steve


  #3  
Old March 25th, 2005, 07:30 PM
sp-googling
external usenet poster
 
Posts: n/a
Default

I think I'm missing something...
What I tried to take from your advise resulted in this mess:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "Periferals!$A$20" Then
Monitors.Range("A20").Value = Periferals.Range("A20").Value
ElseIf Target.Address = "Monitors!$A$20" Then
Periferals.Range("A20").Value = Monitors.Range("A20").Value
End If
End Sub

which I'm putting in "ThisWorkbook" and I'm still not getting anything

  #4  
Old March 28th, 2005, 09:30 PM
sp-googling
external usenet poster
 
Posts: n/a
Default

sorry guys and gals, is this one tougher than I thought?

  #5  
Old March 29th, 2005, 12:22 AM
Dave Peterson
external usenet poster
 
Posts: n/a
Default

I'm not sure I understand what you really want...

If you make a change to A20 on Monitors or Periferals, you want that change to
be echoed onto the other worksheet?

If yes, then this worked ok for me (code is still behind the ThisWorkbook
module):

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Dim OtherSheetName As String
Dim myAddr As String

'only one cell at a time
If Target.Cells.Count 1 Then
Exit Sub
End If

myAddr = "A20"

If Intersect(Target, Sh.Range(myAddr)) Is Nothing Then
Exit Sub
End If

OtherSheetName = ""
Select Case LCase(Sh.Name)
Case Is = "periferals": OtherSheetName = "monitors"
Case Is = "monitors": OtherSheetName = "periferals"
End Select

If OtherSheetName = "" Then
Exit Sub
End If

On Error GoTo errHandler:
Application.EnableEvents = False
Sh.Parent.Worksheets(OtherSheetName).Range(myAddr) .Value = Target.Value

errHandler:
Application.EnableEvents = True

End Sub

By the way, I think the correct spelling for Periferals is Peripherals. If you
change the the worksheet name, remember to change the name in the code, too.


sp-googling wrote:

sorry guys and gals, is this one tougher than I thought?


--

Dave Peterson
  #6  
Old March 30th, 2005, 04:18 PM
sp-googling
external usenet poster
 
Posts: n/a
Default

Excellent stuff Dave. What do I do if I want the two cells to be
different locations rather than just sheets?
Peripherals!A20 and monitors!B4 for example. I know I should have
asked the first time around, but you know how these things go...

btw thanks for the proof reading too :-)

  #7  
Old March 30th, 2005, 07:03 PM
Dave Peterson
external usenet poster
 
Posts: n/a
Default

First, I think I'd take a slightly different approach. I think I'd use just one
worksheet for input and put a formula in the other:

=monitors!b4
(in the peripherals worksheet).

If you lock that cell and protect the sheet, it should be ok.

But if you want...

Option Explicit
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Dim myOtherCell As Range
Dim myPerCell As Range
Dim myMonCell As Range

'only one cell at a time
If Target.Cells.Count 1 Then
Exit Sub
End If

Set myPerCell = Worksheets("peripherals").Range("a20")
Set myMonCell = Worksheets("monitors").Range("b4")

Set myOtherCell = Nothing
If Sh.Name = myPerCell.Parent.Name Then
If Intersect(myPerCell, Target) Is Nothing Then
Exit Sub
Else
Set myOtherCell = myMonCell
End If
ElseIf Sh.Name = myMonCell.Parent.Name Then
If Intersect(myMonCell, Target) Is Nothing Then
Exit Sub
Else
Set myOtherCell = myPerCell
End If
End If

If myOtherCell Is Nothing Then
Exit Sub
End If

On Error GoTo errHandler:
Application.EnableEvents = False
myOtherCell.Value = Target.Value

errHandler:
Application.EnableEvents = True

End Sub




sp-googling wrote:

Excellent stuff Dave. What do I do if I want the two cells to be
different locations rather than just sheets?
Peripherals!A20 and monitors!B4 for example. I know I should have
asked the first time around, but you know how these things go...

btw thanks for the proof reading too :-)


--

Dave Peterson
  #8  
Old March 30th, 2005, 09:07 PM
sp-googling
external usenet poster
 
Posts: n/a
Default

top notch Dave. I'd also use formulas - since I also don't know code -
but this is on a preexisting workbook with numerous formulas
referencing the two cells and the solution you've offered will save the
integrity of the data as well as several hours of changing the
workbook. Your assistance has been very much appreciated.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling data from 1 sheet to another Dave1155 Worksheet Functions 1 January 12th, 2005 05:55 PM
Put same data in cells on two different worksheets (link?) Anthony Setting up and Configuration 4 January 12th, 2005 02:03 AM
How do I get 3 series in sync with the x-axis? zizbird Charts and Charting 10 October 25th, 2004 01:23 PM
decipher log of scanpst.exe km General Discussion 0 July 18th, 2004 09:00 AM
Automatically updating cells on other worksheets when data typed into primary sheet N Davies New Users 4 June 11th, 2004 11:17 PM


All times are GMT +1. The time now is 02:43 AM.


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