How populate last value from file to another

Mussala

Board Regular
Joined
Sep 28, 2022
Messages
74
Office Version
  1. 2019
Platform
  1. Windows
Hello
I have file name(OUTPUT.xlsm) and file name(STOCK.xlsm) and both files are existed in folder(REPORT) in "D:\Users\MUSSS\Desktop\REPORT"
in OUTPUT file contains SUMMARY sheet should populate value in B4 from the last cell contains numeric value in column H in SH sheet for STOCK file , every time run the macro should replace the value in B4 in SUMMARY sheet for OUTPUT file.
thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this:

VBA Code:
Sub populate_last_value()
  Dim wb1 As Workbook, wb2 As Workbook
  Dim sPath As String
  
  sPath = "D:\Users\MUSSS\Desktop\REPORT\"
  
  Set wb1 = Workbooks.Open(sPath & "OUTPUT.xlsm")
  Set wb2 = Workbooks.Open(sPath & "STOCK.xlsm")
  
  wb1.Sheets("SUMMARY").Range("B4").Value = wb2.Sheets("SH").Range("H" & Rows.Count).End(3).Value

  wb1.Close True
  wb2.Close False
End Sub
 
Upvote 0
Solution
Hi,
doesn't seem to work . doesn't show anything , just run but there is no value in B4 for OUTPUT file in summary sheet !
 
Upvote 0
You can put a minisheet or an image of your Stock file from the SH sheet, to see what you have in the last cell of column H.

Also check that on the SH sheet, in the last cell with data you have information, it may be that the last cell has blank spaces, so check carefully which is the last cell with data, you can verify it if you go to the last one cell in column H (H1048576), press the end key once and then the up key. Check where the cursor stops and post the image of the cursor here.
 
Upvote 0
Hi again ,
I tested in another laptop seem to be work , but I don't want close OUTPUT file .just I want close STOCK file after run the macro . I try doing this like you , but still close OUTPUT file and keep STOCK file is open !
VBA Code:
wb1.Close False
  wb2.Close True
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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