Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default How to create a variable selected range

I'm trying to create a macro that will do the following:

1) Goto B1

2) Using the variable number value stored in A1 (i.e., 10), select
B1 and the next nine adjacent cells to the right - creating a range of 10
selected cells (B1:B10).

The goal is to select an X number of cells from a known starting point.

Any ideas ?



- Ronald K.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default How to create a variable selected range


Range("B1").Resize(1, Range("A1").Value2).Select
--
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(Data Rows add-in: Custom Shading, Deleting, Inserting)





"kittronald"
wrote in message
...
I'm trying to create a macro that will do the following:

1) Goto B1

2) Using the variable number value stored in A1 (i.e., 10), select B1 and the next nine
adjacent cells to the right - creating a range of 10 selected cells (B1:B10).

The goal is to select an X number of cells from a known starting point.

Any ideas ?

- Ronald K.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default How to create a variable selected range

Jim,

Thanks, that works !

Using that code, I'm trying to fill down to the last used row.

For example:

A B C D
1 ABC 1 2 3
2 BCD
3 CDE
4 DEF
5 EFG


In this case, B1:D1 would be filled down to row 5.

However, the rows used in column A varies and I'm trying to fill down to
the last used row with code similar to:

Range(Selection, Selection.SpecialCells(xlCellTypeLastCell)).Select

Selection.FillDown

Is there a way to specify the last used row ?



- Ronald K.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default How to create a variable selected range

Hi Ronald,

Am Sat, 20 Aug 2011 02:30:15 -0400 schrieb kittronald:

A B C D
1 ABC 1 2 3
2 BCD
3 CDE
4 DEF
5 EFG

In this case, B1:D1 would be filled down to row 5.


'Last used column
LCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Last used Row
LRow = Cells(Rows.Count, 1).End(xlUp).Row
Range(Cells(1, 2), Cells(1, LCol)).AutoFill _
Destination:=Range(Cells(1, 2), Cells(LRow, LCol))


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default How to create a variable selected range


You might be interested in my recent universal last row function.
It gets the last row from a worksheet, a range or a column and accommodates for Lists or Tables.
free... http://blog.contextures.com/archives...ith-excel-vba/
--
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(Data Rows add-in: Custom Shading, Deleting, Inserting)




"kittronald"
wrote in message
...
Jim,

Thanks, that works !

Using that code, I'm trying to fill down to the last used row.

For example:

A B C D
1 ABC 1 2 3
2 BCD
3 CDE
4 DEF
5 EFG


In this case, B1:D1 would be filled down to row 5.

However, the rows used in column A varies and I'm trying to fill down to the last used row with
code similar to:

Range(Selection, Selection.SpecialCells(xlCellTypeLastCell)).Select

Selection.FillDown

Is there a way to specify the last used row ?



- Ronald K.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default How to create a variable selected range

Jim,

Showoff !

You know, you should do this Excel thing for a living.

Thanks again.



- Ronald K.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default How to create a variable selected range

Claus,

Vielen Dank !



- Ronald K.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default How to create a variable selected range

Hey ,

try this code

Sub Selectandpaste()
Range("B1:D1").Select

Selection.Copy
Range("a1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, Range("B1")).Select
Selection.PasteSpecial

End Sub



On Aug 20, 6:15*am, "kittronald" wrote:
* * I'm trying to create a macro that will do the following:

* * * * 1) Goto B1

* * * * 2) Using the variable number value stored in A1 (i.e., 10), select
B1 and the next nine adjacent cells to the right - creating a range of 10
selected cells (B1:B10).

* * The goal is to select an X number of cells from a known starting point.

* * Any ideas ?

- Ronald K.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default How to create a variable selected range

XLS S,

Thanks, I'll give it a try !



- Ronald K.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default How to create a variable selected range

XLS S brought next idea :
Hey ,

try this code

Sub Selectandpaste()
Range("B1:D1").Select

Selection.Copy
Range("a1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, Range("B1")).Select
Selection.PasteSpecial

End Sub


Why so many lines of code?...

Sub Selectandpaste()
Range("B1:D1").Copy
Range(Range("A1").End(xlDown).Offset(0, 1), Range("B1")).PasteSpecial
Application.CutCopyMode = False
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
vba: attach a variable name to a selected range Jayne22 Excel Programming 4 August 7th 08 10:54 PM
Naming variable range selected by cursor movement Merritt Sakata[_2_] Excel Programming 2 May 29th 08 10:56 AM
how to test whether selected variable is within defined range Abhinandan Excel Programming 0 May 26th 08 08:40 PM
how do i create a formula for selected range? Yin Excel Worksheet Functions 5 September 28th 05 04:55 AM
How do you get a Selected Range address into a variable? Jack Excel Programming 5 November 20th 03 04:09 AM


All times are GMT +1. The time now is 09:25 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"