Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2009, 11:59 PM
Authorized User
 
Join Date: May 2009
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select and copy a range of varying size in VBA

I want to have Access import one worksheet from a workbook with an Access macro. Access macros apparently will not allow you to select a specific worksheet, but will allow you to select a range.

Therefor I need to select a range and assign it a range name in Excel so that Access can then import it.

The complication is that the number of rows will change every time this event occurs and the same range name must be used every time.

To add to the issue, the first row has column headers and must not be included in the selected range.

If I were doing this with the keyboard, I would move to cell A2 and then hold down Shift-Control-End and then assign a name to the selected cells.

Anyone know how to do this in code?
 
Old August 7th, 2009, 10:23 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Can you check if the following gets you closer?

Code:
 
Sub Set_New_Range()
Dim oNewRng As Range
Set oNewRng = Range(Cells(2, 1), Cells.SpecialCells(xlCellTypeLastCell))
MsgBox oNewRng.Address
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Paste Dynamic Range jgrant Excel VBA 1 February 5th, 2008 10:13 PM
varying data range stealthdevil Excel VBA 6 July 27th, 2007 02:30 AM
Copy a worksheet range to a new workbook cej2583 Excel VBA 2 March 14th, 2006 11:55 PM
Excel VBA: Select range of data and plot chart? xitu Excel VBA 1 December 23rd, 2003 04:21 AM
Looping thro' / Copy from Range iwat03 Excel VBA 1 July 3rd, 2003 11:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.