Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Variable rows

Hello,

How do I use a variable to select entire rows? I want to ask the user how
many rows they want to select and then use that number to select the rows.

For instance:
ActiveCell.Offset(0, 0).Rows("1:58").EntireRow.Select
selects 58 rows. I would like to replace the '58' with a variable so that I
can choose how many I want to delete.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Variable rows


Sub AircodeSampleWarning

MyUserinput = Inputbox("Please enter a number")
ActiveCell.Offset(0, 0).Rows("1:" & MyUserInput).EntireRow.Select

End Sub

You may want to consider checking the user input to make sure that it is a
valid entry before executing your selection. If they enter "sfghsg" the code
will error out when trying to select that range.

I could also see the rare but unfortunate instance where a user meant to
type "9" but accidently hits the key twice and deletes 99 rows. Perhaps
consider selecting the rows, then give the user a chance to abort if they
were to hasty and mis-entered their number of rows to delete...

HTH
Keith

"Jwil" wrote:

Hello,

How do I use a variable to select entire rows? I want to ask the user how
many rows they want to select and then use that number to select the rows.

For instance:
ActiveCell.Offset(0, 0).Rows("1:58").EntireRow.Select
selects 58 rows. I would like to replace the '58' with a variable so that I
can choose how many I want to delete.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Variable rows

I would use this instead of the complex statement you are using...

Rws = 58
ActiveCell.Resize(Rws).Select

where I used a variable named Rws to hold the number of rows down from the
active cell to select.

--
Rick (MVP - Excel)


"Jwil" wrote in message
...
Hello,

How do I use a variable to select entire rows? I want to ask the user how
many rows they want to select and then use that number to select the rows.

For instance:
ActiveCell.Offset(0, 0).Rows("1:58").EntireRow.Select
selects 58 rows. I would like to replace the '58' with a variable so that
I
can choose how many I want to delete.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Variable rows

Whoops! I forgot the EntireRow part...

ActiveCell.Resize(V).EntireRow.Select

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
I would use this instead of the complex statement you are using...

Rws = 58
ActiveCell.Resize(Rws).Select

where I used a variable named Rws to hold the number of rows down from the
active cell to select.

--
Rick (MVP - Excel)


"Jwil" wrote in message
...
Hello,

How do I use a variable to select entire rows? I want to ask the user how
many rows they want to select and then use that number to select the
rows.

For instance:
ActiveCell.Offset(0, 0).Rows("1:58").EntireRow.Select
selects 58 rows. I would like to replace the '58' with a variable so
that I
can choose how many I want to delete.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Variable rows

Thanks a lot.

"ker_01" wrote:


Sub AircodeSampleWarning

MyUserinput = Inputbox("Please enter a number")
ActiveCell.Offset(0, 0).Rows("1:" & MyUserInput).EntireRow.Select

End Sub

You may want to consider checking the user input to make sure that it is a
valid entry before executing your selection. If they enter "sfghsg" the code
will error out when trying to select that range.

I could also see the rare but unfortunate instance where a user meant to
type "9" but accidently hits the key twice and deletes 99 rows. Perhaps
consider selecting the rows, then give the user a chance to abort if they
were to hasty and mis-entered their number of rows to delete...

HTH
Keith

"Jwil" wrote:

Hello,

How do I use a variable to select entire rows? I want to ask the user how
many rows they want to select and then use that number to select the rows.

For instance:
ActiveCell.Offset(0, 0).Rows("1:58").EntireRow.Select
selects 58 rows. I would like to replace the '58' with a variable so that I
can choose how many I want to delete.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Variable rows

Thank you very much.

"Rick Rothstein" wrote:

Whoops! I forgot the EntireRow part...

ActiveCell.Resize(V).EntireRow.Select

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
I would use this instead of the complex statement you are using...

Rws = 58
ActiveCell.Resize(Rws).Select

where I used a variable named Rws to hold the number of rows down from the
active cell to select.

--
Rick (MVP - Excel)


"Jwil" wrote in message
...
Hello,

How do I use a variable to select entire rows? I want to ask the user how
many rows they want to select and then use that number to select the
rows.

For instance:
ActiveCell.Offset(0, 0).Rows("1:58").EntireRow.Select
selects 58 rows. I would like to replace the '58' with a variable so
that I
can choose how many I want to delete.




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
Delete Rows based on # of rows (no variable?) DanaK Excel Programming 7 November 3rd 08 12:11 AM
Using variable to select rows Jack77 Excel Programming 1 March 9th 06 07:04 AM
sum and variable rows Jim Excel Worksheet Functions 4 September 7th 05 07:48 PM
How do I sum variable rows in a macro? BamaBarks Excel Programming 2 August 11th 05 06:56 PM
sum variable # of rows Diane Excel Programming 4 May 2nd 05 12:43 PM


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