Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general
external usenet poster
 
Posts: 7
Default two lists of numbers

I am writing an Excel VBA that prompts the user for a series of numbers.
Next I want to compare that list against each cell in a column. If true,
then copy that entire row to another sheet.

I prefer not to have a nested For/Next loop. Is there another way to do
this?

For the VBA people, any simple examples?


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general
external usenet poster
 
Posts: 7,247
Default two lists of numbers

Try something like

Dim V As Variant
Dim FoundCell As Range
V = InputBox("Enter number")
Set FoundCell = Range("A:A").Find(what:=V)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Copy
Destination:=Worksheets("sheet2").Range("A1")
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chas" wrote in message
...
I am writing an Excel VBA that prompts the user for a series of
numbers. Next I want to compare that list against each cell in a
column. If true, then copy that entire row to another sheet.

I prefer not to have a nested For/Next loop. Is there another
way to do this?

For the VBA people, any simple examples?




  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general
external usenet poster
 
Posts: 7
Default two lists of numbers

I have to be careful here. The cell may contain: 5,15,19,20 If the user
entered a 9 in the inputbox, I don't want a match.

"Chip Pearson" wrote in message
...
Try something like

Dim V As Variant
Dim FoundCell As Range
V = InputBox("Enter number")
Set FoundCell = Range("A:A").Find(what:=V)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Copy Destination:=Worksheets("sheet2").Range("A1")
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chas" wrote in message
...
I am writing an Excel VBA that prompts the user for a series of numbers.
Next I want to compare that list against each cell in a column. If true,
then copy that entire row to another sheet.

I prefer not to have a nested For/Next loop. Is there another way to do
this?

For the VBA people, any simple examples?






  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general
external usenet poster
 
Posts: 7,247
Default two lists of numbers

If that's the case, then you probably have to loop through the
range. Find won't do it.

Dim Rng As Range
Dim Arr As Variant
Dim V As Variant
Dim Ndx As Integer
Dim Found As Boolean
V = InputBox("Enter Number")
For Each Rng In Range("A1:A10") '<<< CHANGE RANGE
Arr = Split(Rng.Text, ",")
For Ndx = LBound(Arr) To UBound(Arr)
If Arr(Ndx) = V Then
Found = True
Rng.EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
Exit For
End If
Next Ndx
If Found = True Then
Exit For
End If
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Chas" wrote in message
. ..
I have to be careful here. The cell may contain: 5,15,19,20 If
the user entered a 9 in the inputbox, I don't want a match.

"Chip Pearson" wrote in message
...
Try something like

Dim V As Variant
Dim FoundCell As Range
V = InputBox("Enter number")
Set FoundCell = Range("A:A").Find(what:=V)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Copy
Destination:=Worksheets("sheet2").Range("A1")
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chas" wrote in message
...
I am writing an Excel VBA that prompts the user for a series
of numbers. Next I want to compare that list against each cell
in a column. If true, then copy that entire row to another
sheet.

I prefer not to have a nested For/Next loop. Is there
another way to do this?

For the VBA people, any simple examples?








  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general
external usenet poster
 
Posts: 7
Default two lists of numbers

In the .Copy, don't I have to increment .RANGE to copy to then next row?

Also, how do I know if I am at the last row? In your example, range a1-a10
may have an empty cell. But b1-b10 will always have something until the end
of rows is reached.

"Chip Pearson" wrote in message
...
If that's the case, then you probably have to loop through the range. Find
won't do it.

Dim Rng As Range
Dim Arr As Variant
Dim V As Variant
Dim Ndx As Integer
Dim Found As Boolean
V = InputBox("Enter Number")
For Each Rng In Range("A1:A10") '<<< CHANGE RANGE
Arr = Split(Rng.Text, ",")
For Ndx = LBound(Arr) To UBound(Arr)
If Arr(Ndx) = V Then
Found = True
Rng.EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
Exit For
End If
Next Ndx
If Found = True Then
Exit For
End If
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Chas" wrote in message
. ..
I have to be careful here. The cell may contain: 5,15,19,20 If the user
entered a 9 in the inputbox, I don't want a match.

"Chip Pearson" wrote in message
...
Try something like

Dim V As Variant
Dim FoundCell As Range
V = InputBox("Enter number")
Set FoundCell = Range("A:A").Find(what:=V)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Copy
Destination:=Worksheets("sheet2").Range("A1")
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chas" wrote in message
...
I am writing an Excel VBA that prompts the user for a series of numbers.
Next I want to compare that list against each cell in a column. If
true, then copy that entire row to another sheet.

I prefer not to have a nested For/Next loop. Is there another way to
do this?

For the VBA people, any simple examples?












  #6   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general
external usenet poster
 
Posts: 7,247
Default two lists of numbers

Yes, you should increment the copy destination.


Dim Rng As Range
Dim Arr As Variant
Dim V As Variant
Dim Ndx As Integer
Dim Found As Boolean
Dim DestRng As Range
Set DestRng = Worksheets("Sheet2").Range("A1") '<<< CHANGE RANGE
V = InputBox("Enter Number")
For Each Rng In Range("A1:A10") '<<< CHANGE RANGE
Arr = Split(Rng.Text, ",")
For Ndx = LBound(Arr) To UBound(Arr)
If Arr(Ndx) = V Then
Found = True
Rng.EntireRow.Copy _
Destination:=DestRng
Set DestRng = DestRng(2, 1)
Exit For
End If
Next Ndx
If Found = True Then
Exit For
End If
Next Rng

"Chas" wrote in message
...
In the .Copy, don't I have to increment .RANGE to copy to then
next row?

Also, how do I know if I am at the last row? In your example,
range a1-a10 may have an empty cell. But b1-b10 will always
have something until the end of rows is reached.

"Chip Pearson" wrote in message
...
If that's the case, then you probably have to loop through the
range. Find won't do it.

Dim Rng As Range
Dim Arr As Variant
Dim V As Variant
Dim Ndx As Integer
Dim Found As Boolean
V = InputBox("Enter Number")
For Each Rng In Range("A1:A10") '<<< CHANGE RANGE
Arr = Split(Rng.Text, ",")
For Ndx = LBound(Arr) To UBound(Arr)
If Arr(Ndx) = V Then
Found = True
Rng.EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
Exit For
End If
Next Ndx
If Found = True Then
Exit For
End If
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Chas" wrote in message
. ..
I have to be careful here. The cell may contain: 5,15,19,20
If the user entered a 9 in the inputbox, I don't want a match.

"Chip Pearson" wrote in message
...
Try something like

Dim V As Variant
Dim FoundCell As Range
V = InputBox("Enter number")
Set FoundCell = Range("A:A").Find(what:=V)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Copy
Destination:=Worksheets("sheet2").Range("A1")
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chas" wrote in message
...
I am writing an Excel VBA that prompts the user for a series
of numbers. Next I want to compare that list against each
cell in a column. If true, then copy that entire row to
another sheet.

I prefer not to have a nested For/Next loop. Is there
another way to do this?

For the VBA people, any simple examples?












  #7   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general
external usenet poster
 
Posts: 7
Default two lists of numbers

Thank you for your time and responses.

"Chip Pearson" wrote in message
...
Yes, you should increment the copy destination.


Dim Rng As Range
Dim Arr As Variant
Dim V As Variant
Dim Ndx As Integer
Dim Found As Boolean
Dim DestRng As Range
Set DestRng = Worksheets("Sheet2").Range("A1") '<<< CHANGE RANGE
V = InputBox("Enter Number")
For Each Rng In Range("A1:A10") '<<< CHANGE RANGE
Arr = Split(Rng.Text, ",")
For Ndx = LBound(Arr) To UBound(Arr)
If Arr(Ndx) = V Then
Found = True
Rng.EntireRow.Copy _
Destination:=DestRng
Set DestRng = DestRng(2, 1)
Exit For
End If
Next Ndx
If Found = True Then
Exit For
End If
Next Rng

"Chas" wrote in message
...
In the .Copy, don't I have to increment .RANGE to copy to then next row?

Also, how do I know if I am at the last row? In your example, range
a1-a10 may have an empty cell. But b1-b10 will always have something
until the end of rows is reached.

"Chip Pearson" wrote in message
...
If that's the case, then you probably have to loop through the range.
Find won't do it.

Dim Rng As Range
Dim Arr As Variant
Dim V As Variant
Dim Ndx As Integer
Dim Found As Boolean
V = InputBox("Enter Number")
For Each Rng In Range("A1:A10") '<<< CHANGE RANGE
Arr = Split(Rng.Text, ",")
For Ndx = LBound(Arr) To UBound(Arr)
If Arr(Ndx) = V Then
Found = True
Rng.EntireRow.Copy _
Destination:=Worksheets("Sheet2").Range("A1")
Exit For
End If
Next Ndx
If Found = True Then
Exit For
End If
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Chas" wrote in message
. ..
I have to be careful here. The cell may contain: 5,15,19,20 If the user
entered a 9 in the inputbox, I don't want a match.

"Chip Pearson" wrote in message
...
Try something like

Dim V As Variant
Dim FoundCell As Range
V = InputBox("Enter number")
Set FoundCell = Range("A:A").Find(what:=V)
If Not FoundCell Is Nothing Then
FoundCell.EntireRow.Copy
Destination:=Worksheets("sheet2").Range("A1")
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chas" wrote in message
...
I am writing an Excel VBA that prompts the user for a series of
numbers. Next I want to compare that list against each cell in a
column. If true, then copy that entire row to another sheet.

I prefer not to have a nested For/Next loop. Is there another way to
do this?

For the VBA people, any simple examples?














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
Making Lists of numbers nebula Excel Discussion (Misc queries) 5 May 10th 08 01:57 AM
How to determine the correlation between two lists of numbers? Eric Excel Discussion (Misc queries) 4 November 13th 07 04:12 AM
Converting lists of numbers Eliot Excel Discussion (Misc queries) 2 August 10th 06 07:42 PM
solving lists of numbers problems richard Excel Discussion (Misc queries) 1 July 27th 05 09:18 PM
How do I compare two lists of numbers? demebe123 Excel Worksheet Functions 1 April 22nd 05 12:32 AM


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