So where is the error??
Dim wb As Workbook
Dim wbMEgdF As Workbook, wbMEgdB As Workbook ' don't be concerned about these names.
Dim rH As Range, rF As Range
Dim sFileName As String
Dim LenH As Long, LenF As Long
Application.ScreenUpdating = False ' turn off the screen updating
'Show the open dialog and pass the selected _
file name To the String variable "sFileName"
sFileName = Application.GetOpenFilename
'They have cancelled.
If sFileName = "False" Then Exit Sub
Set wb = Workbooks.Open(sFileName)
If InStr(1, ThisWorkbook.Name, "megdf", vbTextCompare) Then
Set wbMEgdF = ThisWorkbook
Set wbMEgdB = wb
Else
Set wbMEgdF = wb
Set wbMEgdB = ThisWorkbook
MsgBox "If here in the code, the code is not in the expected workbook, quitting"
Exit Sub
End If
LenH = wbMEgdF.Worksheets("Data&Parms").Range("B1").Value ' column H of Data&Parms of wbMEgdF
LenF = wbMEgdF.Worksheets("Data&Parms").Range("B3").Value ' column F of Output of wbMEgdF
If LenH = 0 Then
MsgBox "No entry in MEgdF!Data&Parms.B1 length of data in Data&Parms"
Exit Sub
End If
If LenF = 0 Then
MsgBox "No entry in MEgdF!Data&Parms.B3 - length of data in output"
Exit Sub
End If
Set rH = wbMEgdF.Worksheets("Data&Parms").Range("H1").Resize(LenH, 1)
Set rF = wbMEgdF.Worksheets("Output").Range("F1").Resize(LenF, 1)
rF.Copy
wbMEgdB.Worksheets("Data&Parms").Range("H1").PasteSpecial xlValues
rH.Copy
wbMEgdB.Worksheets("Output").Range("G1").PasteSpecial xlValues
wbMEgdB.Save ' making a guess you want to save wbMEgdB.xls
wbMEgdB.Close
Set wb = Nothing ' free memory
Set wbMEgdB = Nothing
Application.ScreenUpdating = True ' turn on the screen updating
MsgBox "data transfer complete"
End Sub
Bookmarks