LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Macro to select a list of values greater than or equal to a va

Thank you very much! This will help me out a great deal with a daily report
that I prepare at my plant. I was not familiar with the Union or Resize
functions. This is what I like about these discussion groups, they are
fantastic learning experiences.

"Vergel Adriano" wrote:

Doogie,

You would do it somewhat like this:

'Find values =100 in Col A, copy that and the 2 cells its right. paste in
Col D
Sub test()
Dim rng As Range
Dim c As Range
Dim rngCopy As Range

With ActiveSheet
Set rng = .Range(.Range("A1"), .Range("A65535").End(xlUp))
End With
For Each c In rng
If c.Value = 100 Then
If rngCopy Is Nothing Then
Set rngCopy = c.Resize(1, 3)
Else
Set rngCopy = Union(rngCopy, c.Resize(1, 3))
End If
End If
Next c
If Not rngCopy Is Nothing Then
rngCopy.Copy ActiveSheet.Range("D1")
End If

End Sub




--
Hope that helps.

Vergel Adriano


"DOOGIE" wrote:

I tried this and it works great! One more question: if I also want to copy
the values in the 2 columns to the right of each cell that contains a value
greater than or equal to 100, how would I do that? Would I use Offset?

"Vergel Adriano" wrote:

will copy values =100 in column A and paste in column B.

Sub test()
Dim rng As Range
Dim c As Range
Dim rngCopy As Range

With ActiveSheet
Set rng = .Range(.Range("A1"), .Range("A65535").End(xlUp))
End With
For Each c In rng
If c.Value = 100 Then
If rngCopy Is Nothing Then
Set rngCopy = c
Else
Set rngCopy = Union(rngCopy, c)
End If
End If
Next c
If Not rngCopy Is Nothing Then
rngCopy.Copy ActiveSheet.Range("B1")
End If

End Sub


--
Hope that helps.

Vergel Adriano


"DOOGIE" wrote:

I am trying to write a macro that will search through a list of values (this
list will vary in size) for all values greater than or equal to a specific
value (say =100). I want to activate all the cells containing those values
and copy them to another location. Can anyone help with this?



 
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
Greater/Less Than or Equal To Hoov Excel Discussion (Misc queries) 5 May 14th 09 05:54 PM
selecting values from a list to equal a given value [email protected] Excel Worksheet Functions 3 December 23rd 08 11:09 PM
counting the last 3 values not equal to x in a list bouncebackability Excel Worksheet Functions 3 April 9th 08 07:01 PM
Select from List of names to equal a specific rate Shirley Excel Worksheet Functions 3 December 20th 05 05:29 PM
list values equal in 2 worksheets? NEVA LOCKETT Excel Worksheet Functions 2 February 23rd 05 03:21 PM


All times are GMT +1. The time now is 09:37 AM.

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"