Hello, everyone.
I am new to VBA and trying to automate some of the tasks that my fellow coworkers have to do. Currently, I need to load data into a excel worksheet with data retrieved from another. I think I am close but at my wits end. I'm sure the problem is some small thing I am missing. Here is how I want it to work - the user opens up a workbook form and will press F8 to execute the macro. The user will then choose the excel document with the data they want to load. All that is working fine - I just don't get any value back. Currently, I am currently just trying to get the value for one cell back. I'll add others after the macro is working. Below is my code. I'm sure it is not pretty to you experienced coders. Thank you in advance for your help.
Option Explicit
Sub GetData()
Dim b1 As Workbook, b2 As Workbook
Dim MaxStr1 As Double
Dim MaxStr2 As Double
Dim vFile As Variant
Set b1 = ActiveWorkbook
vFile = Application.GetOpenFilename("Excel-files,*.xlsx", 1, "Select One File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Workbooks.Open vFile
'Set Source Workbook
Set b2 = ActiveWorkbook
' Get value for Max Straightness
MaxStr2 = b2.Worksheets("Sheet1").Range("A16").Value
MaxStr1 = MaxStr2
' Set Target Workbook
Set b1 = ActiveWorkbook
b1.Worksheets("Sheet1").Range("B16").Value = MaxStr1
b2.Close
End Sub
Lynda
Bookmarks