Update another Workbook from a diffrent workbook.

Karlos588

New Member
Joined
Apr 26, 2020
Messages
10
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Afternoon All, I currently have a Macro as a Worksheet change, that when a cell in a set column changes it open another workbook and marks the matching number down as "Invoiced"
How ever, I now need to change this from a worksheet change into a button click. How do I go about this I've tried a few things. but nothing is working.
I need to change the Target into the actual Column, but I'm unsure how to go about this.

Below is my Macro as worksheet change.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False

Dim TrackerWb As Workbook
Dim InvListWb As Workbook
Dim TrackerWs As Worksheet
Dim searchRegion As Range
Dim InterlabRef As Range

Set InvListWb = ActiveWorkbook
Set InterlabRef = Target

If Target.Column = 14 Then

    Set TrackerWb = Workbooks.Open("W:\WCL\Certification\Finance\Interlab Tracker.xlsm")
    Set TrackerWs = TrackerWb.Sheets("Invoices")

    Set searchRegion = TrackerWs.Range("K1:K2000")
    Set cell = searchRegion.Find(what:=InterlabRef, LookAt:=xlWhole, SearchFormat:=False)

    If cell Is Nothing Then
TrackerWb.Close False
Exit Sub
Else
cell.Offset(0, 2).Value = "Invoiced"
TrackerWb.Save
TrackerWb.Close
    End If


End If

Application.ScreenUpdating = True

End Sub

Thanks in Advance!

Karl
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Assuming you intend to have the button work on the active cell you can simply replace Target with ActiveCell. Then put the button in place and move the code to the button's associated macro.
 
Upvote 0
I basically need the button to open the second workbook and match the Interlab Ref, any that match it needs to mark as "Invoiced"
 
Upvote 0
Open your VBA Editor, Insert a new Module (Insert, Module). Paste in the code below. Then go to your Excel file. From the Developer tab of the ribbon, insert a button from the Forms section (NOT ActiveX!). RIght-click the button and choose Assign Macro. Enter the macro name "UpdateTracker" (without the quotes) into the box and click OK.

Code:
Sub UpdateTracker()

Application.ScreenUpdating = False

Dim TrackerWb As Workbook
Dim InvListWb As Workbook
Dim TrackerWs As Worksheet
Dim searchRegion As Range
Dim InterlabRef As Range

Set InvListWb = ActiveWorkbook
Set InterlabRef = ActiveCell

If Activecell.Column = 14 Then

    Set TrackerWb = Workbooks.Open("W:\WCL\Certification\Finance\Interlab Tracker.xlsm")
    Set TrackerWs = TrackerWb.Sheets("Invoices")

    Set searchRegion = TrackerWs.Range("K1:K2000")
    Set cell = searchRegion.Find(what:=InterlabRef, LookAt:=xlWhole, SearchFormat:=False)

    If cell Is Nothing Then
TrackerWb.Close False
Exit Sub
Else
cell.Offset(0, 2).Value = "Invoiced"
TrackerWb.Save
TrackerWb.Close
    End If


End If

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
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