Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default How to move cells with VBA?

After exporting a table from Access into Excel, I need to move the data down
45 rows via automation.

This is working, but seems inefficient:

Do While fr < 45
xlapp.Workbooks(strXlsFile).Worksheets(sn).Cells(f r + 1, "A"). _
EntireRow.Insert shift:=xlDown
fr = fr + 1
Loop

Is there a better way to move this contiguous block of cells? There is no
other data in the worksheet, and the cells always begin at A1.

Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default How to move cells with VBA?

To cut and move:

ActiveSheet.UsedRange.Cut _
Destination:=Range("A45")


To move and clear:

Dim x As Integer
x = ActiveSheet.UsedRange.Rows.Count
ActiveSheet.UsedRange.Copy _
Destination:=Range("A45")
Range(Rows(1), Rows(x)).ClearContents

To move values and clear:

Dim x As Integer
x = ActiveSheet.UsedRange.Rows.Count

ActiveSheet.UsedRange.Offset(45, 0).Value = ActiveSheet.UsedRange.Value
Range(Rows(1), Rows(x)).ClearContents

--
steveB

Remove "AYN" from email to respond
"deko" wrote in message
. com...
After exporting a table from Access into Excel, I need to move the data
down
45 rows via automation.

This is working, but seems inefficient:

Do While fr < 45
xlapp.Workbooks(strXlsFile).Worksheets(sn).Cells(f r + 1, "A"). _
EntireRow.Insert shift:=xlDown
fr = fr + 1
Loop

Is there a better way to move this contiguous block of cells? There is no
other data in the worksheet, and the cells always begin at A1.

Thanks in advance.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default How to move cells with VBA?

Sub InsertRows()
Rows("1:44").Insert
End Sub


That was easy....

xlapp.Workbooks(strXlsFile).Worksheets(sn).Rows("1 :44").Insert

Thanks!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default How to move cells with VBA?

glad to help

--
Don Guillett
SalesAid Software

"deko" wrote in message
om...
Sub InsertRows()
Rows("1:44").Insert
End Sub


That was easy....

xlapp.Workbooks(strXlsFile).Worksheets(sn).Rows("1 :44").Insert

Thanks!




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
Can references (to cells being sorted) move with the cells? Zack Setting up and Configuration of Excel 1 January 16th 08 01:50 PM
Move cells according to value saman110 via OfficeKB.com Excel Discussion (Misc queries) 3 November 2nd 07 12:15 AM
Sorting cells: a list behind the cells do not move with the cell Ross M Excel Discussion (Misc queries) 2 September 21st 06 12:14 PM
Move 2 cells to right Pasmatos Excel Discussion (Misc queries) 4 November 10th 05 09:23 AM
Move cells Wild Bill[_2_] Excel Programming 0 August 27th 03 11:46 AM


All times are GMT +1. The time now is 03:12 PM.

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

About Us

"It's about Microsoft Excel"