Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default how to select cells dynamically in excel macro?

Following is the sample macro. I want to get 2 worksheets, one beside the
other on a single new worksheet.

Sub Macro7()
Workbooks.Open Filename:="C:\Sujatha\Excel\Jan_sales.xls"
Application.Goto Reference:="JAN_SALES"
Selection.Copy
Windows("Book3.xls").Activate
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
Workbooks.Open Filename:="C:\Sujatha\Excel\Feb_sales.xls"
Application.Goto Reference:="FEB_SALES"
Selection.Copy
Windows("Book3.xls").Activate
ActiveSheet.Paste
End Sub

I have specified 'Range("D1").Select' explictly. Suppose I don't know where
the first range ends, I want the macro to go to the last +2 columns and then
make the next copy.

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default how to select cells dynamically in excel macro?

Excel user

Try this:

Dim rPaste as Range
Dim wbCopy as Workbook

Set wbCopy = Workbooks.Open("C:\Sujatha\Excel\Jan_sales.xls")
Set rPaste = Workbooks("Book3.xls").Sheets(1).Range("A1")
wbCopy.Sheets(1).Range("JAN_SALES").Copy Destination:=rPaste

Set rPaste = rPaste.End(xlToRight).Offset(0,2)
wbCopy.Close False

Set wbCopy = Workbooks.Open("C:\Sujatha\Excel\Feb_sales.xls")
wbCopy.Sheets(1).Range("FEB_SALES").Copy Destination:=rPaste
wbCopy.Close False

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com


"Excel user" <Excel wrote in message
...
Following is the sample macro. I want to get 2 worksheets, one beside the
other on a single new worksheet.

Sub Macro7()
Workbooks.Open Filename:="C:\Sujatha\Excel\Jan_sales.xls"
Application.Goto Reference:="JAN_SALES"
Selection.Copy
Windows("Book3.xls").Activate
ActiveSheet.Paste
Range("D1").Select
Application.CutCopyMode = False
Workbooks.Open Filename:="C:\Sujatha\Excel\Feb_sales.xls"
Application.Goto Reference:="FEB_SALES"
Selection.Copy
Windows("Book3.xls").Activate
ActiveSheet.Paste
End Sub

I have specified 'Range("D1").Select' explictly. Suppose I don't know

where
the first range ends, I want the macro to go to the last +2 columns and

then
make the next copy.

Thanks in advance



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
Macro to select cells without a certain value and select a menu it Guy[_2_] Excel Worksheet Functions 9 January 2nd 09 05:21 PM
How do I change the size of cells dynamically in Excel? Little Eagle Excel Worksheet Functions 1 October 4th 07 01:09 AM
Help with Dynamically changing Range in Excel Macro runsrealfast Excel Discussion (Misc queries) 4 July 16th 07 10:44 PM
dynamically select a range of cells for use in a formula isofuncurves Excel Worksheet Functions 1 February 2nd 06 01:34 AM
How to dynamically select a validation list from data in a cell? sessc Excel Discussion (Misc queries) 1 July 28th 05 06:11 PM


All times are GMT +1. The time now is 05:17 AM.

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"