Transfer data from one workbook to another in different folders via vba.

MS_1977

New Member
Joined
Jan 8, 2021
Messages
14
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
I'm having trouble with a vba code, to copy data from one Workbook to another, in different folders. Would there be any way to accomplish this process via code?
 
In the "Programação de Cargas D+1.xlsb" workbook, the "BD-Planejado" sheet tab name has a space at the end. Please delete that extra space in the sheet name and re-save the file and close it. Then try this macro:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim LastRow As Long, lRow As Long, srcWS As Worksheet, desWB As Workbook, desWS As Worksheet
    Set srcWS = ThisWorkbook.Sheets("Consolidado_De_Cargas")
    Set desWB = Workbooks.Open("\\Loja5470\pac$\Delivery\TRANSPORTE ESTRATÉGICO\38 - Planejamento Logistico\Roteirização\Programação de Cargas D+1.xlsb")
    Set desWS = Sheets("BD-Planejado")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lRow = desWS.Columns(2).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    With srcWS
        Union(.Range("C3:C" & LastRow - 3), .Range("B3:B" & LastRow - 3), .Range("H3:H" & LastRow - 3), .Range("AR3:AR" & LastRow - 3), .Range("U3:U" & LastRow - 3)).Copy
        desWS.Range("B" & lRow).PasteSpecial xlPasteValues
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Na pasta de trabalho "Programação de Cargas D + 1.xlsb", o nome da guia da planilha "BD-Planejado" tem um espaço no final. Exclua esse espaço extra no nome da planilha, salve novamente o arquivo e feche-o. Em seguida, tente esta macro:
[CODE = vba]
Sub CopyData ()
Application.ScreenUpdating = False
Dim LastRow As Long, lRow As Long, srcWS As Worksheet, desWB As Workbook, desWS As Worksheet
Set srcWS = ThisWorkbook.Sheets ("Consolidado_De_Cargas")
Set desWB = Workbooks.Open ("\\ Loja5470 \ pac $ \ Delivery \ TRANSPORTE ESTRATÉGICO \ 38 - Planejamento Logistico \ Roteirização \ Programação de Cargas D + 1.xlsb")
Definir desWS = Folhas ("BD-Planejado")
LastRow = srcWS.Cells.Find ("*", SearchOrder: = xlByRows, SearchDirection: = xlPrevious) .Row
lRow = desWS.Columns (2) .Find ("*", SearchOrder: = xlByRows, SearchDirection: = xlPrevious) .Row + 1
Com srcWS
Union (.Range ("C3: C" & LastRow - 3), .Range ("B3: B" & LastRow - 3), .Range ("H3: H" & LastRow - 3), .Range ("AR3: AR "& LastRow - 3), .Range (" U3: U "& LastRow - 3)). Copiar
desWS.Range ("B" & lRow) .PasteSpecial xlPasteValues
Terminar com
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
[/CÓDIGO]
 
Upvote 0
Mumps, Sensational It worked perfectly my friend, thank you very much for your support and clear weather.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,541
Latest member
iparraguirre89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top