The End If statements are in full code, I assumed this part of the code was giving me the issue so I uploaded just that part. My bad!
I have attached 2 files, Destination and Source.
When i run trhough the code in Step Into mode, it works right on point. But, when the complete macro is run - file do get open, prompts user to write the sheet name. The sheets, rows, columns everything is blank (Grey zone).Sub LoadData()
Dim ws As Worksheet
Dim desiredSheetName As String
Dim c As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ans = MsgBox("Choose the file to retrive the data?", vbYesNo, "Choose Source")
If ans = vbYes Then
myfile = Application.GetOpenFilename(, , "Browse for Workbook")
If myfile <> False Then
ThisWorkbook.Sheets("Destination").Range("AA2") = myfile
Set src_data = Workbooks.Open(myfile)
On Error Resume Next
desiredSheetName = InputBox("Select any cell inside the target sheet: ",type:=8).worksheet.name ' Here i tried with .parent also
sht = desiredSheetName
On Error GoTo 0
Set dest = ThisWorkbook.Worksheets("Destination")
src_data.Activate
'Get the Last Row Details of Source and Destination workbooks
lastcell = src_data.Sheets(sht).Cells(Rows.Count, "C").End(xlUp).Row
LastRowD = dest.Cells(dest.Rows.Count, "F").End(xlUp).Offset(0).Row
src_data.Activate
Sheets(sht).Select
Range("A:B,D:D").Select
Selection.Copy
dest.Activate
Range("F1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
src_data.Close False
dest.Select
End If
Else
Exit Sub
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Bookmarks