any place you have .Worksheets(1)
you are SPECIFYING the first worksheet in the workbook!

If you want to import into the "currently active sheet"
then replace Worksheets(1) with ActiveSheet
when specifying where the data is to be placed.

Or, add your new sheet at the beginning of the file,
which will make it worksheets(1)
 
Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------




________________________________
From: Best Of Luck <akras...@gmail.com>
To: excel-macros@googlegroups.com
Sent: Tue, November 13, 2012 2:47:18 PM
Subject: $$Excel-Macros$$ Re: Guide me in modifying the included code to import 
data into the current active sheet


Prince thanks for the code. In Your code you are opening the target file. In my 
case the target file will already be open. I will have Sheet1, Sheet2, Sheet3, 
Sheet4 and so on. Every month I will open the spreadhseet to a new Sheet and 
run 
the data import. My code works but always imports the data in the first sheet  
so I need a way to import it into the current sheet.

thanks in advance
On Friday, November 9, 2012 12:25:42 PM UTC-6, Best Of Luck wrote:
Hi,
>
>I was using the code below to import data into a Excel 2010 workbook with only 
>one sheet. I now have multiple sheets and I wont this macro to only import the 
>data into the active sheet. Here is the code. 
>
>
>Sub ImportCity()
>' Get customer workbook...
>Dim customerBook As Workbook
>Dim filter As String
>Dim caption As String
>Dim customerFilename As String
>Dim customerWorkbook As Workbook
>Dim targetWorkbook As Workbook
>' make weak assumption that active workbook is the target
>Set targetWorkbook = Application.ActiveWorkbook
>' get the customer workbook
>filter = "Text files (*.xlsx),*.xlsx"
>caption = "Please Select an input file "
>customerFilename = Application.GetOpenFilename( filter, , caption)
>Set customerWorkbook = Application.Workbooks.Open( customerFilename)
>' assume range is A1 - C10 in sheet1
>' copy data from customer to target workbook
>Dim targetSheet As Worksheet
>Set targetSheet = targetWorkbook.Worksheets(1)
>Dim sourceSheet As Worksheet
>Set sourceSheet = customerWorkbook.Worksheets(1)
>targetSheet.Range("A8", "V100").Value = sourceSheet.Range("A8", "V100").Value
>' Close customer workbook
>customerWorkbook.Close
>End Sub-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES (1120+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

 
6) Jobs posting is not allowed.
 
7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners 
and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros?hl=en.

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros?hl=en.


Reply via email to