I am trying to pull a file-(1) inside a excel file(2) by browsing in my computer. And pull data from the file-(1) from different cells randomly and paste it in file(2).
I am beginner and trying to copy bits and parts from different program to make it work.I have complied a code that works okay.
I face some problem. a) As I am copying and pasting each cell one by one the program is too long and my screen flashes white many times. (I tried Application.EnableEvents = False but it didn't work. May be I don't know where to insert it exactly)
b) can it be done once I copy the data from file(1) Inside file(2), Can the file(1) be closed(or loose from browse link).
c)can the code be made short ? (like copying together and pasting together etc).I have to copy data from 10 more cells.
Sub PullData() Dim uploadfile As Variant Dim uploader As Workbook Dim CurrentBook As Workbook Set CurrentBook = ActiveWorkbook MsgBox ("Please select uploader file to be reviewed") uploadfile = Application.GetOpenFilename() If uploadfile = "False" Then Exit Sub End If Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("L10").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO29").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("L11").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO26").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("H24").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO13").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("H27").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO18").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("H26").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO17").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("L9").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO25").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("E42").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO34").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("E43").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO33").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("E48").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO45").PasteSpecial Paste:=xlPasteValues Workbooks.Open uploadfile Set uploader = ActiveWorkbook With uploader Application.CutCopyMode = False Range("E50").Copy End With CurrentBook.Activate Sheets("Calculations").Range("AO44").PasteSpecial Paste:=xlPasteValues End Sub
Application.screenupdating = Falseand yes, you can set ranges to each other instead of copy/pasting.Withstatement changeRange...to.Worksheets("WorksheetName").Range...TheWithstatement removes the need to retype objects.