Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Bill (Unique as my name)
 
Posts: n/a
Default Any way to loop this in VBA?

If ComboBox3 = 1 Then
Range("R199").Select
ElseIf ComboBox3 = 2 Then
Range("R227").Select
ElseIf ComboBox3 = 3 Then
Range("R255").Select
ElseIf ComboBox3 = 4 Then
Range("R283").Select
ElseIf ComboBox3 = 5 Then
Range("R311").Select
ElseIf ComboBox3 = 6 Then
Range("R339").Select
ElseIf ComboBox3 = 7 Then
Range("R367").Select
ElseIf ComboBox3 = 8 Then
Range("R395").Select
ElseIf ComboBox3 = 9 Then
Range("R423").Select
ElseIf ComboBox3 = 10 Then
Range("R451").Select
ElseIf ComboBox3 = 11 Then
Range("R479").Select
ElseIf ComboBox3 = 12 Then
Range("R507").Select
ElseIf ComboBox3 = 13 Then
Range("R535").Select
ElseIf ComboBox3 = 14 Then
Range("R563").Select
ElseIf ComboBox3 = 15 Then
Range("R591").Select
ElseIf ComboBox3 = 16 Then
Range("R619").Select
ElseIf ComboBox3 = 17 Then
Range("R647").Select
ElseIf ComboBox3 = 18 Then
Range("R675").Select
ElseIf ComboBox3 = 19 Then
Range("R703").Select
ElseIf ComboBox3 = 20 Then
Range("R731").Select
ElseIf ComboBox3 = 21 Then
Range("R759").Select
ElseIf ComboBox3 = 22 Then
Range("R787").Select
ElseIf ComboBox3 = 23 Then
Range("R815").Select
ElseIf ComboBox3 = 24 Then
Range("R843").Select
ElseIf ComboBox3 = 25 Then
Range("R871").Select
ElseIf ComboBox3 = 26 Then
Range("R899").Select

Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default Any way to loop this in VBA?

You can set that code to trigger at an "On Change" or maybe a "MouseUp"
event. Is that the kind of loop you need?

PS Don't forget your End If line!

  #3   Report Post  
Posted to microsoft.public.excel.misc
Bill Martin
 
Posts: n/a
Default Any way to loop this in VBA?

It kind of looks to me like a good candidate for a CASE statement. Go into
Excel's VBA help window and look up SELECT CASE STATEMENT.

Alternatively, I haven't examined every case but it looks like your Range
statements just go up in increments of 28? If so, then try:

X = 171 + 28*ComboBox3
Range("R" & X).select

Bill
--------------------------

On 22 Feb 2006 07:44:46 -0800, Bill (Unique as my name) wrote:

If ComboBox3 = 1 Then
Range("R199").Select
ElseIf ComboBox3 = 2 Then
Range("R227").Select
ElseIf ComboBox3 = 3 Then
Range("R255").Select
ElseIf ComboBox3 = 4 Then
Range("R283").Select
ElseIf ComboBox3 = 5 Then
Range("R311").Select
ElseIf ComboBox3 = 6 Then
Range("R339").Select
ElseIf ComboBox3 = 7 Then
Range("R367").Select
ElseIf ComboBox3 = 8 Then
Range("R395").Select
ElseIf ComboBox3 = 9 Then
Range("R423").Select
ElseIf ComboBox3 = 10 Then
Range("R451").Select
ElseIf ComboBox3 = 11 Then
Range("R479").Select
ElseIf ComboBox3 = 12 Then
Range("R507").Select
ElseIf ComboBox3 = 13 Then
Range("R535").Select
ElseIf ComboBox3 = 14 Then
Range("R563").Select
ElseIf ComboBox3 = 15 Then
Range("R591").Select
ElseIf ComboBox3 = 16 Then
Range("R619").Select
ElseIf ComboBox3 = 17 Then
Range("R647").Select
ElseIf ComboBox3 = 18 Then
Range("R675").Select
ElseIf ComboBox3 = 19 Then
Range("R703").Select
ElseIf ComboBox3 = 20 Then
Range("R731").Select
ElseIf ComboBox3 = 21 Then
Range("R759").Select
ElseIf ComboBox3 = 22 Then
Range("R787").Select
ElseIf ComboBox3 = 23 Then
Range("R815").Select
ElseIf ComboBox3 = 24 Then
Range("R843").Select
ElseIf ComboBox3 = 25 Then
Range("R871").Select
ElseIf ComboBox3 = 26 Then
Range("R899").Select

Thanks in advance.

  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Any way to loop this in VBA?

It looks like there's 28 rows between each one.

range("R" & 199 + 28 * (combobox3-1)).select



"Bill (Unique as my name)" wrote:

If ComboBox3 = 1 Then
Range("R199").Select
ElseIf ComboBox3 = 2 Then
Range("R227").Select
ElseIf ComboBox3 = 3 Then
Range("R255").Select
ElseIf ComboBox3 = 4 Then
Range("R283").Select
ElseIf ComboBox3 = 5 Then
Range("R311").Select
ElseIf ComboBox3 = 6 Then
Range("R339").Select
ElseIf ComboBox3 = 7 Then
Range("R367").Select
ElseIf ComboBox3 = 8 Then
Range("R395").Select
ElseIf ComboBox3 = 9 Then
Range("R423").Select
ElseIf ComboBox3 = 10 Then
Range("R451").Select
ElseIf ComboBox3 = 11 Then
Range("R479").Select
ElseIf ComboBox3 = 12 Then
Range("R507").Select
ElseIf ComboBox3 = 13 Then
Range("R535").Select
ElseIf ComboBox3 = 14 Then
Range("R563").Select
ElseIf ComboBox3 = 15 Then
Range("R591").Select
ElseIf ComboBox3 = 16 Then
Range("R619").Select
ElseIf ComboBox3 = 17 Then
Range("R647").Select
ElseIf ComboBox3 = 18 Then
Range("R675").Select
ElseIf ComboBox3 = 19 Then
Range("R703").Select
ElseIf ComboBox3 = 20 Then
Range("R731").Select
ElseIf ComboBox3 = 21 Then
Range("R759").Select
ElseIf ComboBox3 = 22 Then
Range("R787").Select
ElseIf ComboBox3 = 23 Then
Range("R815").Select
ElseIf ComboBox3 = 24 Then
Range("R843").Select
ElseIf ComboBox3 = 25 Then
Range("R871").Select
ElseIf ComboBox3 = 26 Then
Range("R899").Select

Thanks in advance.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default Any way to loop this in VBA?

Alternatively, you can first store the ranges in an array. This can be
usefull if they're not a mathematical increment (like +28).

Option Base 1 'so that the first array index is 1, needs to be placed
in the very beginning of the module code

Sub SelectTheRange()
Dim arrRanges() as String
arrRanges = Array("R100","R12","R244","R512","R10:U10", .....)
Range(arrRanges(ComboBox3)).Select
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.misc
Bill (Unique as my name)
 
Posts: n/a
Default Any way to loop this in VBA?

I don't know how to show my appreciation.
I am numb with bliss.
You guys are just plain awesome.

Thanks again for the help.

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
Loop gone crazy Dave Peterson Excel Discussion (Misc queries) 4 December 16th 05 03:38 PM
Do Loop Noemi Excel Discussion (Misc queries) 0 December 8th 05 10:43 PM
Help with Do...Loop Noemi Excel Discussion (Misc queries) 1 December 7th 05 12:59 AM
VB for excel, how do I loop through code steve hobden via OfficeKB.com Excel Discussion (Misc queries) 2 June 9th 05 01:59 PM
loop trough e-mail address list to send task lists with outlook Paul. Excel Discussion (Misc queries) 2 April 14th 05 11:48 AM


All times are GMT +1. The time now is 11:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"