Import data macro based on X criteria

robocop1906

Board Regular
Joined
Jan 15, 2003
Messages
143
I have a spreadsheet that I’d like to import information from but to an existing tab that already has a header row. I also only want to import a certain range of data and have it based on a specific column criteria.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Path: C:\Documents and Settings<o:p></o:p>
Source File<o:p></o:p>
- File Name: Financial Workbook_Data_Store_Cleanse.xlsm<o:p></o:p>
- Tab Name: RawStampData<o:p></o:p>
- Copy Range: A2:AD<o:p></o:p>
- Criteria: Where Column AH = “Non-DEU IS”<o:p></o:p>
Destination: <o:p></o:p>
- File Name: 2011 DEU Projects - Financial Workbook.xlsm<o:p></o:p>
- Tab Name: StAmP NonCIL Data<o:p></o:p>
- Paste Range:A2:AD<o:p></o:p>
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Code:
Sub MoveData()
Dim r As Long
Application.ScreenUpdating = False

Workbooks.Open Filename:= _
        "C:\Documents and Settings\2011 DEU Projects - Financial Workbook.xlsm"
With Workbooks("Financial Workbook_Data_Store_Cleanse").Sheets("RawStampData")
For r = 30000 To 2 Step -1
    If .Cells(r, 34).Value = "Non-Deu Is" Then
        .Range("A2:D2").Copy (Workbooks("2011 DEU Projects - Financial Workbook").Sheets("StAmP NonCiL Data").Range("A" & r))
End If
Next r
End With
Application.ScreenUpdating = True

End Sub
Try this and let me know how it works...and as always test this on a copy of your real data first!
 
Last edited:
Upvote 0
I get the following error. on this line of code-->With Workbooks("Financial Workbook_Data_Store_Cleanse").Sheets("RawStampData")

Run-time error ‘-2147352565 (8002000b)’:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Index refers beyond end of list.<o:p></o:p>
 
Upvote 0
I am not familiar with that error, but my guess is there might be a spelling error or not exact match with either the workbook or sheet name.

Make sure there are no leading or trailing spaces in the name of either wbook or wsheet.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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