Auto Update Cell Value

tim220225

New Member
Joined
Jun 4, 2012
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Not very good with VBA code here and need some help please. I have two workbooks within the same folder and typically only have one workbook open. I have multiple years of data in the closed workbook. When I am in the open workbook I can call for the data of any year by selecting the year via a drop-down box in a specific cell which is "B1". I need to have the year that shows in the open workbook automatically update the year cell which is "B1" in the closed workbook whenever it is changed in the open work-book. I assume that the code needs to open/update/close the workbook which needs to be updated "behind the scenes".

This works well for me when both files are open but I need to make this work when only one file is open. Can someone help me with a simple code example please?

Tim
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Put the following code in the events of your sheet 1 of your open workbook.
I guess the sheet is first in both books.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B1")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
        '
        ruta = ThisWorkbook.Path & "\"
        arch = "other workbook.xlsx"     'name of the closed book
        '
        Application.ScreenUpdating = False
        Set l2 = Workbooks.Open(ruta & arch)
        l2.Sheets(1).Range("B1").Value = Target.Value
        l2.Save
        l2.Close
    End If
End Sub





Let me know any questions.
 
Upvote 0
Dante,

Thank you for the reply. I inserted your code in the worksheet of the opened workbook. When I change the value of the referenced cell I get the following error:


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
ruta = ThisWorkbook.Path & ""
arch = "C:Desktop\PCL Load Billing 11.29.2018.xlsx"
Application.ScreenUpdating = False
Set 12 = Workbooks.Open(ruta & arch)
12.Sheets(1).Range("A2").Value = Target.Value
12.Save
12.Close
End If
End Sub

On Debug the line that begins with Set 12 is yellow. Not sure what the issue is.

Tim
 
Upvote 0
"l2" is the letter l, not the number 1, however, I changed the letter l to wb


I also corrected the path

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A2")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
        ruta = "C:\Desktop\"
        arch = "PCL Load Billing 11.29.2018.xlsx"
        Application.ScreenUpdating = False
        Set wb2 = Workbooks.Open(ruta & arch)
        wb2.Sheets(1).Range("A2").Value = Target.Value
        wb2.Save
        wb2.Close
    End If
End Sub



Try and tell me
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top