excel - Pulling data from a closed workbook macro -


Issues related to dragging data from a closed workbook using macros.

Enter image details here

The above image is the main workbook In the macro cell A1, which I would like to insert, you can see that a file name is a place - this is the location of the closed secondary workbook, which I would like to draw data.

I would like to move the macro to the place that is present in cell A1, in the closed workbook, copied cells A1: J5000, and then in this workbook starting in A7 (i.e. A7: J5007) Paste it. The reason is that the file name exists in the location A1, due to the fact that it will change; However I would always like to take the macro that is shown in A1 (for example, if A1 is to be changed from '... \ test00218_data.csv' to '... \ test00001_data.csv' then I Taking data from new location, test00001)

Since then, I've written a macro that I believe that all the sheets called "raw data x" will open and paste essential data into the appropriate fields of the primary sheet; The code is as follows:

  sub PullClosedData () in the form of a slow filepath string x = 1 to 1 step1 filePath = sheets ("raw data" and.). (1, 1). Value Workbook Open filename: = filepath sheets ("raw data 1"). Range ("A7: J2 113"). Value = ActiveWorkBook Active Sheet.Range ("A1: J 2107") Next X & Subscription   

When I run it, I get a runtime error 9 (out of range) I believe There is something with this script's "ActiveWorkbook.ActiveSheet" portion, but it is uncertain how to rewrite it and avoid error.

First of all, do not leave the path in a cell, which you plan to overwrite. Instead, create a separate sheet containing important input parameters (see the examples given below; I am calling that sheet "system").

Enter image details here

The code source below "Raw Data 1" from the book pulls data from workbooks for "raw data 3".

  • Make sure that you define your workbooks in variables (TargetWb and SourceWb)
  • When referring to a worksheet, always specify that it contains many workbooks (for example, TargetWb.ActiveWorksheet, Bus ActiveWorksheet)

    .

      Set the workbook as a slow targetWb in the form of a slow filepath string sound source as the targetWb = ActiveWorkbook filePath = TargetWb.Sheets ("AP1"). Range ("A1") Price Set Source = WB = Workbooks For open (phylax) I = 1 to 3 SourceWb.Sheets ("raw data" & amp; i) Category ("A1: J5000") .Copy Destination: = TargetWb.Sheets ("raw data" & amp; i). Range ("A1: J5000") NextM SourceWb.Close Ms Gbbox "All done!" End Sub    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -