PC Review


Reply
Thread Tools Rate Thread

How to create a variable selected range

 
 
kittronald
Guest
Posts: n/a
 
      20th Aug 2011
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.


 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      20th Aug 2011

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" <(E-Mail Removed)>
wrote in message
news:j2n1se$ii7$(E-Mail Removed)...
> 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.



 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      20th Aug 2011
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, B11 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.


 
Reply With Quote
 
Claus Busch
Guest
Posts: n/a
 
      20th Aug 2011
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, B11 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
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      20th Aug 2011

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" <(E-Mail Removed)>
wrote in message
news:j2nka2$ts1$(E-Mail Removed)...
> 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, B11 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.
>



 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      21st Aug 2011
Jim,

Showoff !

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

Thanks again.



- Ronald K.


 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      21st Aug 2011
Claus,

Vielen Dank !



- Ronald K.


 
Reply With Quote
 
XLS S
Guest
Posts: n/a
 
      24th Aug 2011
Hey ,

try this code

Sub Selectandpaste()
Range("B11").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" <kittron...@yahoo.com> 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.


 
Reply With Quote
 
kittronald
Guest
Posts: n/a
 
      25th Aug 2011
XLS S,

Thanks, I'll give it a try !



- Ronald K.


 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      25th Aug 2011
XLS S brought next idea :
> Hey ,
>
> try this code
>
> Sub Selectandpaste()
> Range("B11").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("B11").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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba: attach a variable name to a selected range Jayne22 Microsoft Excel Programming 4 7th Aug 2008 10:54 PM
Naming variable range selected by cursor movement Merritt Sakata Microsoft Excel Programming 2 29th May 2008 10:56 AM
how to test whether selected variable is within defined range in V Abhinandan Microsoft Excel Programming 2 26th May 2008 08:40 PM
how do i create a formula for selected range? =?Utf-8?B?WWlu?= Microsoft Excel Worksheet Functions 5 28th Sep 2005 04:55 AM
How do you get a Selected Range address into a variable? Jack Microsoft Excel Programming 9 20th Nov 2003 04:41 AM


Features
 

Advertising
 

Newsgroups
 


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