Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Loop and extend selection

I have the following values in the A column:
1
2
2
2
3
3

I want to loop through the values by starting in cell A1 and extend the
selection as long as the values are the same. That means in the above
example that all the cells with the value 2 should be selected. How can
I do that?

I'm very grateful for fast answer!

Regards,

S

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Loop and extend selection

I don't understand what you're asking for. My understanding of what
you've said is I select cell A1 (with a value of 1) and extend the
selection till it changes. This means I would end with just cell A1
seleced. If I had:

1
1
1
2
2

The I would end with A1:A3 selected. Please clarify so we can help.


wrote:
I have the following values in the A column:
1
2
2
2
3
3

I want to loop through the values by starting in cell A1 and extend the
selection as long as the values are the same. That means in the above
example that all the cells with the value 2 should be selected. How can
I do that?

I'm very grateful for fast answer!

Regards,

S


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Loop and extend selection

You are correct. I didn't explain it as I should!

Regards,

S

John Fuller skrev:

I don't understand what you're asking for. My understanding of what
you've said is I select cell A1 (with a value of 1) and extend the
selection till it changes. This means I would end with just cell A1
seleced. If I had:

1
1
1
2
2

The I would end with A1:A3 selected. Please clarify so we can help.


wrote:
I have the following values in the A column:
1
2
2
2
3
3

I want to loop through the values by starting in cell A1 and extend the
selection as long as the values are the same. That means in the above
example that all the cells with the value 2 should be selected. How can
I do that?

I'm very grateful for fast answer!

Regards,

S


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Loop and extend selection

Here try this to start you off. This will choose multiple cells
throughout Column A


Sub MyMultiSelect()
Dim mycells As Object, myrange As Range, MyString As String
Set myrange = [A:A]
For Each mycells In myrange
If mycells.Value = [a1] Then
If MyString = Empty Then
MyString = mycells.Address
Else
MyString = MyString & ", " & mycells.Address
End If
End If
Next
Range(MyString).Select
End Sub


wrote:
You are correct. I didn't explain it as I should!

Regards,

S

John Fuller skrev:

I don't understand what you're asking for. My understanding of what
you've said is I select cell A1 (with a value of 1) and extend the
selection till it changes. This means I would end with just cell A1
seleced. If I had:

1
1
1
2
2

The I would end with A1:A3 selected. Please clarify so we can help.


wrote:
I have the following values in the A column:
1
2
2
2
3
3

I want to loop through the values by starting in cell A1 and extend the
selection as long as the values are the same. That means in the above
example that all the cells with the value 2 should be selected. How can
I do that?

I'm very grateful for fast answer!

Regards,

S


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Loop and extend selection

Sorry, I copied the wrong code. The previous code will loop through and
find all values matching Range A1 in the whole Column A, this code will
stop once the value changes in column A. As you can see it's the same
code with just a If...Then statement telling itself to stop the
For...Next once the two values are different

Cheers,

Sandy

Sub MyMultiSelect()
Dim mycells As Object, myrange As Range, MyString As String
Set myrange = [A:A]
For Each mycells In myrange
'Exit if values are different
If Not mycells.Value = [A1] Then Exit For
If mycells.Value = [A1] Then
If MyString = Empty Then
MyString = mycells.Address
Else
MyString = MyString & ", " & mycells.Address
End If
End If
Next
Range(MyString).Select
End Sub

Sandy wrote:
Here try this to start you off. This will choose multiple cells
throughout Column A


Sub MyMultiSelect()
Dim mycells As Object, myrange As Range, MyString As String
Set myrange = [A:A]
For Each mycells In myrange
If mycells.Value = [a1] Then
If MyString = Empty Then
MyString = mycells.Address
Else
MyString = MyString & ", " & mycells.Address
End If
End If
Next
Range(MyString).Select
End Sub


wrote:
You are correct. I didn't explain it as I should!

Regards,

S

John Fuller skrev:

I don't understand what you're asking for. My understanding of what
you've said is I select cell A1 (with a value of 1) and extend the
selection till it changes. This means I would end with just cell A1
seleced. If I had:

1
1
1
2
2

The I would end with A1:A3 selected. Please clarify so we can help.


wrote:
I have the following values in the A column:
1
2
2
2
3
3

I want to loop through the values by starting in cell A1 and extend the
selection as long as the values are the same. That means in the above
example that all the cells with the value 2 should be selected. How can
I do that?

I'm very grateful for fast answer!

Regards,

S


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
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
Loop row selection copy with blank spaces Dave[_60_] Excel Programming 3 February 13th 06 04:33 PM
Using loop for selection macro akoobra[_2_] Excel Programming 1 January 28th 05 03:14 PM
Date selection loop Roger[_8_] Excel Programming 12 September 26th 04 12:53 AM
extend selection indu aronson Excel Programming 1 December 4th 03 09:31 PM


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