How to find information from another spreadsheet in Excel

Asked

Viewed 3,272 times

2

I have a system that generates spreadsheets . xls daily, example "matriz_070120150900.xls". Where the numbers represent the day and time 07/01/2015 at 09:00. I created a spreadsheet for managing this data called manage.xls. How do I manage.xls identify the matriz_xxxxxxxxx.xls file so that I can perform operations of the matriz_xxxxxxxxx.xls data in the spreadsheet manages.xls?

Note: matriz_070120150900.xls varies according to the day. Today is matriz_070120150900.xls, tomorrow will be another matriz_080120151000.xls

I can search from a spreadsheet with the fixed name:

Exemplo:

matriz_070120150900.xls
A1 - Salário
B1 - R$100.000

gerencia.xls
A1 - Diretor
B1 - =[matriz_070120150900.xls]Salário!$B$1
  • From what I understand, How to get information from another spreadsheet you already know how to do. However I would like to do it dynamically and not manually?

  • Yes, exactly. However, I need to add the values of the spreadsheet (dynamically) matriz_070120150900.xls with the worksheet of the next day matriz_080120151000.xls, which will be generated from 08/01 to 10:00

  • The system generates spreadsheets with the same columns. I need the worksheet generating.xls to identify the worksheets with the name that starts with "matriz_" and add the values of column "B1", for example.

  • It is not the solution but a great help for your question, look at this link http://www.vbaexpress.com/kb/getarticle.php?kb_id=1042

  • 1

    the spreadsheet gerencia.xls take the information of the previous spreadsheets or only the one of the current day? All spreadsheets, including the gerencia.xls, are in the same folder?

2 answers

1

Try using formula =INDIRECT

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Formula used in this example: CELL B3 table manages.xls =INDIRECT( CONCATENATE( "["; B1; ". xlsx]Plan1! B1"); TRUE)

0

These are some steps to accomplish what you want here...

  1. Identify the spreadsheets

From what I saw in your example, the name varies not only according to the date, but also the time, because in one of the cited files you placed '0900' = '9:00h' and another with '1000' = '10:00'.

1.1 If you have a pattern that changes only the date, it is easier, because it would generate in the file 'manage.xls' a routine to create the name of the files in order to get a specific date, the day or the day before, if applicable.

' Para pegar o arquivo de hoje
="matriz_"&TEXTO(AGORA();"ddmmaaaa")&"1000"

Adapt the above example to find the desired date at the desired time, if a fixed time.

1.2 If you don’t have this fixed file name, you can create a specific folder that will only have the file you want to read and do a routine (function) to read all the files in this folder according to this template I found:

Lists all files in a folder

This code is quite complete and can be adapted to search from a fixed and fixed.xls folder as needed.

After knowing the file that has to be referenced, you can fetch the data!

  1. Data search

2.1 The search for the data can be direct as shown in your example, if it works as you wish, ok!

2.2 If you want to copy this data, you can have a temporary 'tab' to copy the data, work and write to the desired table. Depending on the complexity of the search, if you have filters to be made etc, I use a direct connection via ODBC (Excel Files) to filter using SQL the data I want and the necessary filters. In some project I have made used this function below that can be adapted according to your demand:

Sub SQLPesq(ByRef WHAREHOUSE As String, ByRef PATHFILE As String, ByRef PATH As String)

' Macro para pesquisar no arquivo selecionado, dados do armazém selecionado

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
    "ODBC;DSN=Excel Files;DBQ=" & PATHFILE & ";DefaultDir" _
    ), Array( _
    "=" & PATH & ";DriverId=1046;MaxBufferSize=2048;PageTimeout=5;" _
    )), Destination:=Range(WHAREHOUSE)).QueryTable
    .CommandText = Array( _
    "SELECT `RESUMO$`.Clientes, `RESUMO$`.`Descrição do Armazém`, `RESUMO$`.IE, `RESUMO$`.`Tipo de Grão`, `RESUMO$`.`Total Geral`" & Chr(13) & "" & Chr(10) & _
    "FROM `RESUMO$` `RESUMO$`" _
    )
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .ListObject.DisplayName = "tbl" & WHAREHOUSE
    .Refresh BackgroundQuery:=False
End With

End Sub

After this search would have the way to work the data, manipulate, format and write this information in the table, but I think it would be outside the scope of what you asked.

I hope I’ve helped!

  • Although there is nothing wrong with the use of VBA, I would give preference to the answer using formulas, without VBA. The reason is that it is more accessible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.