Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA Code for selection rows

Ok I know how to write the code for selecting a row. Here is an example:
Rows("8:27").Select

What if instead of the number i want to use vairables such as:
Rows("x:y").Select

Can anyone tell me how to do this? If you can please email


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default VBA Code for selection rows

Try this:

Rows(x & ":" & y).Select

only text goes in " " and variables stay out.

--
steveB

Remove "AYN" from email to respond
" wrote in
message ...
Ok I know how to write the code for selecting a row. Here is an example:
Rows("8:27").Select

What if instead of the number i want to use vairables such as:
Rows("x:y").Select

Can anyone tell me how to do this? If you can please email




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default VBA Code for selection rows

What sort of thing do you want to do with this facility? It will help to get
you a better solution.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Code for selection rows

Copy and paste this procedure into a module and then run it on a worksheet.
If this doesn't give you hours of enjoyment, I don't know what will.



Sub Rows_SelectVariable()

Dim ibxTop As String
Dim ibxBottom As String
Dim sngTop As Single
Dim sngBottom As Single


ibxTop = InputBox("Enter the row number that's the TOP row of your rows
selection", _
"What is your UPPERMOST Row ?", _
ActiveCell.Offset(1, 0).Row)

If Len(ibxTop) 0 Then
sngBottom = CSng(ibxTop) + 1
Else
sngBottom = ActiveCell.Offset(2, 0).Row
End If

ibxBottom = InputBox("Enter the row number that's the BOTTOM row of your
rows selection", _
"What is your LOWERMOST Row ?", _
sngBottom)


If Len(ibxTop) = 0 Or Len(ibxBottom) = 0 Then

MsgBox "You clicked the ""Cancel"" button for one or both of the
requested row numbers. " & _
"This procedure will be aborted." _
, vbOKOnly + vbCritical, _
"Apprarently, you don't want or need no stinking rows ... "

ActiveCell.Select

Exit Sub

ElseIf ibxTop = 0 Or ibxBottom = 0 Then

MsgBox "You entered an invalid row address of (zero)." & _
"This procedure will be aborted." _
, vbOKOnly + vbCritical, _
"Apprarently, you don't want or need no stinking rows ... "

ActiveCell.Select

Exit Sub

End If

sngTop = CSng(ibxTop)
sngBottom = CSng(ibxBottom)

If sngBottom < sngTop Then

MsgBox "You entered an invalid pair of row addresses:" & vbCr & vbCr
& _
"You entered " & Format(sngTop, "0") & " for your TOP row." &
vbCr & _
"You entered " & Format(sngBottom, "0") & " for your BOTTOM
row." & vbCr & vbCr & _
"The value for BOTTOM row CAN'T BE LESS THAN THE TOP row. " &
vbCr & _
"The BOTTOM row MUST BE GREATER THAN OR --for " & _
"a one-row selection-- EQUAL TO the top row." & vbCr & vbCr & _
"This procedure will be aborted." _
, vbOKOnly + vbCritical, _
"Apprarently, you don't want or need no stinking rows ... "

sngTop = 0
sngBottom = 0

Exit Sub

Else

MsgBox "The " & Format(sngBottom - sngTop + 1, "0") & _
"-contiguous-row selection you've indicated is: " & vbCr & vbCr
& _
"(" & sngTop & ":" & sngBottom & ")" _
, vbOKOnly + vbInformation, _
"I got your rows ... "


ActiveCell.Offset(sngTop - ActiveCell.Row, 0).Range(Cells(1, 1),
Cells(sngBottom - sngTop + 1, 1)).EntireRow.Select

End If

sngTop = 0
sngBottom = 0

End Sub




" wrote:

Ok I know how to write the code for selecting a row. Here is an example:
Rows("8:27").Select

What if instead of the number i want to use vairables such as:
Rows("x:y").Select

Can anyone tell me how to do this? If you can please email


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
Help with selection code Jeff[_45_] Excel Programming 4 February 14th 05 04:37 PM
Cell selection code ToddG Excel Programming 2 September 22nd 04 09:26 PM
Need Code For Selection SMILE Excel Programming 3 August 10th 04 12:34 PM
Selection code sixfivebeastman Excel Programming 3 May 27th 04 08:54 PM
Print Selection in Code Donna Brooks Excel Programming 2 July 25th 03 04:35 PM


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