VBA to Transfer (Certain) Data from One Workbook to Another

nc_waggoner

New Member
Joined
Sep 2, 2016
Messages
21
PLEASE HELP! I will describe this as detailed as possible.

GOAL: To auto-transfer data (criteria based/no blanks) from an online-based Sharepoint file to a separate workbook for analysis

From (Source) File = “LabData.xlsx” located online at http://sharepoint.com/Labs/LabData (made up)

To (Analysis) File = “LabData Analysis.xlsx”

THINGS TO CONSIDER:

  1. Due to user/input error, only valid data should be transferred. No blanks with the best method being a named range…in the below example only transfer rows where the “DIFF” is between -3 and 3.
  2. Preferred, but optional, to auto-open the source file from online so that I can do everything locally.

DATA EXAMPLE: (In the below example, samples 1, 6, and 10 should be omitted from the transfer for not meeting the criteria )

DATESAMPLETANKTEST 1SAMPLE WTTEST 2DIFF
8/1/2016130351.2531.53.5
8/2/201624030.5233-2.5
8/3/201635031.51.7532-0.5
8/4/20164132.5134-1.5
8/5/201651033.52330.5
8/6/20166130.5130.5
8/7/201671031.5233-1.5
8/8/201682032.51.5320.5
8/9/201693033.51.2534-0.5
8/10/2016104030.5134-3.5

<tbody>
</tbody><colgroup><col><col><col><col><col><col span="2"></colgroup>
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this code:
Code:
Option Explicit


Sub MoveData()
'Copy to Master Spreadsheet
Dim lr As Long
Dim lrC As Long
Dim wbTarget As Workbook 'Master
Dim wbThis As Workbook  'Current Open Workbook
Dim strName As String 'Name for source sheet/target workbook
Dim thePath As String  'Path for Master Spreadsheet
Dim i As Long


    Application.ScreenUpdating = False


'set the current active workbook
    Set wbThis = ActiveWorkbook
'set the target workbook name
    strName = "labdataanalysis"
'set the path to the Comments Spreadsheet
'change thepath to your path for the file
    thePath = "C:\Users\Alan\Desktop\"
'open Master Spreadsheet
    Set wbTarget = Workbooks.Open(thePath & strName & ".xlsx")
'Activate the Target Workbook
    wbTarget.Activate
'activate source workbook
    wbThis.Activate
'find the last row in column A to determine the range to copy
    lr = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
'clear any thing on the clipboard to mazimize available memory
    Application.CutCopyMode = False
'Determine rows to copy
    For i = 1 To lr
    'Find the last row in the target workbook
    lrC = wbTarget.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    If wbThis.Sheets("Sheet1").Range("G" & i) >= -3 And wbThis.Sheets("Sheet1").Range("G" & i) <= 3 Then
    Range("G" & i).EntireRow.Copy wbTarget.Sheets("sheet1").Range("A" & lrC + 1)
    End If
    Next i
'Clear the clipboard
    Application.CutCopyMode = False
    wbTarget.Save
    wbTarget.Close
    wbThis.Activate
    Application.ScreenUpdating = True
         
'clear memory
    Set wbTarget = Nothing
    Set wbThis = Nothing
    MsgBox "Data Transferred"
End Sub

Put the code in the source file labdata and give it an .xlsm extention. Note that you will have to change thepath variable to your path. I have not worked with sharepoint so I am unsure of what that would be. I tested using just my desktop as a target. Also check the spelling of both files to ensure that the code and the files are exactly the same. ie. spaces and capitalization
 
Upvote 0

Forum statistics

Threads
1,214,873
Messages
6,122,029
Members
449,061
Latest member
TheRealJoaquin

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