Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Pasting Data without shifting Down rows

Hi, below is the code for importing a file into 'Imported Data'

Problem arises when the file is imported, references to the file in another
Worksheet (even stored as $constants) shift downward. The imported file
currently has 70 records, so if a new file is imported, the references shift
each time by 70 rows, therefore screwing up the formula results.

How can I clear the sheet, and paste the data other than using the
Selection.Insert Shift:=xlDown function?

Sub Import_Data()
' Import_Data Macro recorded 14/02/2007 by (me)
' This macro imports the data from the selected file output from the database
' This is limited to *.xls (default) or *.csv file formats

Dim oWB

Workbooks("SOiEM Genie v1.xls").Activate
Sheets("Imported Data").Activate
'ActiveWorksheet.Unprotect
Selection.CurrentRegion.Clear


With Application.FileDialog(msoFileDialogOpen)
FileToOpen = Application _
.GetOpenFilename("Comma Separated Values (*.csv),*.csv,Microsoft
Excel (*.xls),*.xls,All Files (*.*),*.*")

Workbooks.Open FileToOpen
Set oWB = Workbooks.Open(FileToOpen)
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks("SOiEM Genie v1.xls").Activate
Sheets("Imported Data").Activate
Range("A1").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
oWB.Close

End With
'ActiveWorksheet.Protect
Sheets("Main").Activate
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Pasting Data without shifting Down rows

Don't worry, I fixed it -
Replace: Selection.Insert Shift:=xlDown
With ActiveSheet.Paste Destination:=Worksheets("Imported Data").Range("A1")

"D Zandveld" wrote:

Hi, below is the code for importing a file into 'Imported Data'

Problem arises when the file is imported, references to the file in another
Worksheet (even stored as $constants) shift downward. The imported file
currently has 70 records, so if a new file is imported, the references shift
each time by 70 rows, therefore screwing up the formula results.

How can I clear the sheet, and paste the data other than using the
Selection.Insert Shift:=xlDown function?

Sub Import_Data()
' Import_Data Macro recorded 14/02/2007 by (me)
' This macro imports the data from the selected file output from the database
' This is limited to *.xls (default) or *.csv file formats

Dim oWB

Workbooks("SOiEM Genie v1.xls").Activate
Sheets("Imported Data").Activate
'ActiveWorksheet.Unprotect
Selection.CurrentRegion.Clear


With Application.FileDialog(msoFileDialogOpen)
FileToOpen = Application _
.GetOpenFilename("Comma Separated Values (*.csv),*.csv,Microsoft
Excel (*.xls),*.xls,All Files (*.*),*.*")

Workbooks.Open FileToOpen
Set oWB = Workbooks.Open(FileToOpen)
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks("SOiEM Genie v1.xls").Activate
Sheets("Imported Data").Activate
Range("A1").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
oWB.Close

End With
'ActiveWorksheet.Protect
Sheets("Main").Activate
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Pasting Data without shifting Down rows

Note the substituted code where you were using insert.

Workbooks.Open FileToOpen
Set oWB = Workbooks.Open(FileToOpen)
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks("SOiEM Genie v1.xls").Activate
Sheets("Imported Data").Activate
postRow =
Worksheets(1).UsedRange.SpecialCells(xlCellTypeLas tCell).Row + 2
Cells(postRow, 1).PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
oWB.Close

Try this on a copy before installing on the functional workbook.


"D Zandveld" wrote:

Hi, below is the code for importing a file into 'Imported Data'

Problem arises when the file is imported, references to the file in another
Worksheet (even stored as $constants) shift downward. The imported file
currently has 70 records, so if a new file is imported, the references shift
each time by 70 rows, therefore screwing up the formula results.

How can I clear the sheet, and paste the data other than using the
Selection.Insert Shift:=xlDown function?

Sub Import_Data()
' Import_Data Macro recorded 14/02/2007 by (me)
' This macro imports the data from the selected file output from the database
' This is limited to *.xls (default) or *.csv file formats

Dim oWB

Workbooks("SOiEM Genie v1.xls").Activate
Sheets("Imported Data").Activate
'ActiveWorksheet.Unprotect
Selection.CurrentRegion.Clear


With Application.FileDialog(msoFileDialogOpen)
FileToOpen = Application _
.GetOpenFilename("Comma Separated Values (*.csv),*.csv,Microsoft
Excel (*.xls),*.xls,All Files (*.*),*.*")

Workbooks.Open FileToOpen
Set oWB = Workbooks.Open(FileToOpen)
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks("SOiEM Genie v1.xls").Activate
Sheets("Imported Data").Activate
Range("A1").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
oWB.Close

End With
'ActiveWorksheet.Protect
Sheets("Main").Activate
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting Rows and Shifting Up - Repost D.Parker Excel Discussion (Misc queries) 14 October 11th 07 04:58 AM
Shifting rows into columns biggg_fish Excel Discussion (Misc queries) 2 March 28th 07 03:13 AM
Pasting rows below the last row with data? flurry[_4_] Excel Programming 2 May 16th 06 12:24 PM
Looping through rows and shifting certain contents Steven Excel Programming 3 January 13th 06 08:41 PM
Shifting Date from all data on one row to several rows ChuckW Excel Discussion (Misc queries) 1 June 8th 05 07:56 PM


All times are GMT +1. The time now is 07:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"