How add procedures from file to another using userform to populate value

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
146
Office Version
  1. 2019
Platform
  1. Windows
Hi
I have this code
VBA Code:
dim ws as worksheet
set ws=sheet1
With ws
lr = .Range("A" & Rows.Count).End(xlUp).Row
TextBox1.Value = .Range("E" & lr).Value
End With
should populate the value in textbox1 based on the last value is existed in lastrow for column E
but I want populate last value in column E from closed to open file contains form .

I mean the code should be in open file contains form and should bring the value from closed file

so the closed file contains values in column E and and should populate the last value in column E into textbox1 in open file

two both files are existed in this folder "C:\Users\MKKL\Desktop\REP\"

so how add the procedures about external source ?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I would suggest that you amend your code so that it opens the source workbook, retrieves the desired value, and then closes the source workbook. And I would suggest that you add Application.ScreenUpdating = False at the beginning of your code and Application.ScreenUpdating = True at the end of your code. This will make it so that you won't see the workbook being opened and closed.

Hope this helps!
 
Upvote 0
Do you do anything with textbox1 or does textbox1 only have the value from the closed E?
Does the last value always end up in the same cell or could that cell be different each time?

Then the rest of the sheet works off of that?
 
Upvote 0
thanks Domenic,
but I no know how do that , that's why I ask here to help me the members how add the procedure .
 
Upvote 0
Try the following code...

VBA Code:
    Dim sourceFolderName As String
    sourceFolderName = "C:\Users\MKKL\Desktop\REP\"
    If Right(sourceFolderName, 1) <> "\" Then
        sourceFolderName = sourceFolderName & "\"
    End If
    
    Dim sourceFilename As String
    sourceFilename = "Book2.xlsx" 'change the workbook name accordingly
    
    If Len(Dir(sourceFolderName & sourceFilename, vbNormal)) = 0 Then
        MsgBox "'" & sourceFolderName & sourceFilename & "' not found!", vbExclamation
        Exit Sub
    End If
    
    Application.ScreenUpdating = False

    Dim sourceWorkbook As Workbook
    Set sourceWorkbook = Workbooks.Open(Filename:=sourceFolderName & sourceFilename, ReadOnly:=True)
    
    Dim lastValue As Variant
    With sourceWorkbook.Worksheets("Sheet1") 'change the sheet name accordingly
        lastValue = .Cells(.Rows.Count, "E").End(xlUp).Value
    End With
    
    sourceWorkbook.Close SaveChanges:=False
    
    Application.ScreenUpdating = True
    
    TextBox1.Value = lastValue

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,215,337
Messages
6,124,340
Members
449,155
Latest member
ravioli44

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