Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
nat nat is offline
external usenet poster
 
Posts: 7
Default Code Needed - new user

Hello,
Please help me to write a code to accomplish the following:
..I have a list of account numbers listed in column A
(starting from the second row or A2)
..I need the macro to go down the list (while there is
still data) and determine if the account numbers are valid
(against the list of invalid account numbers)
..And if it finds the invalid account number it should
delete the entire row

Of course I can determine the invalid accounts by using
the VLookUp function and then manually delete the rows but
it would be great if it can be down automatically (via
macro).

Please help and thank you in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Code Needed - new user

Try this

With the list of account numbers in column A in Sheet1
And the list of invalid numbers in column A in Sheet2

Sub Test()
Dim r As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
For r = .UsedRange.Rows.Count To 2 Step -1
If Application.CountIf(Sheets("Sheet2").Columns("A"), _
.Cells(r, "A").Value) 0 Then .Rows(r).Delete
Next
End With
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"nat" wrote in message ...
Hello,
Please help me to write a code to accomplish the following:
.I have a list of account numbers listed in column A
(starting from the second row or A2)
.I need the macro to go down the list (while there is
still data) and determine if the account numbers are valid
(against the list of invalid account numbers)
.And if it finds the invalid account number it should
delete the entire row

Of course I can determine the invalid accounts by using
the VLookUp function and then manually delete the rows but
it would be great if it can be down automatically (via
macro).

Please help and thank you in advance.




  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Code Needed - new user

Is there a way to avoid using Sheet2? Can I have a macro
that will loop from one record down to another until it is
blank and compares the value (from that record) to the
list of invalid values. But I do not want to save the
list of invalid values in the same workbook. Is there a
way to declare the list in the body of the macro itself?
I'm not very familiar with Arrays or how to use them but
an Array looks like a list of values. So if I can have a
code that will take the value (let's say in cell A2),
compare it to the list of values (saved in the macro) and
delete the row if the match is not found, that would be
great. Any suggestions?


-----Original Message-----
Try this

With the list of account numbers in column A in Sheet1
And the list of invalid numbers in column A in Sheet2

Sub Test()
Dim r As Long
Application.ScreenUpdating = False
With Worksheets("Sheet1")
For r = .UsedRange.Rows.Count To 2 Step -1
If Application.CountIf(Sheets

("Sheet2").Columns("A"), _
.Cells(r, "A").Value) 0 Then .Rows(r).Delete
Next
End With
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"nat" wrote in

message ...
Hello,
Please help me to write a code to accomplish the

following:
.I have a list of account numbers listed in column A
(starting from the second row or A2)
.I need the macro to go down the list (while there is
still data) and determine if the account numbers are

valid
(against the list of invalid account numbers)
.And if it finds the invalid account number it should
delete the entire row

Of course I can determine the invalid accounts by using
the VLookUp function and then manually delete the rows

but
it would be great if it can be down automatically (via
macro).

Please help and thank you in advance.




.

  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Code Needed - new user

This solution still requires to keep the list of values in
b1:b3 (which I'm trying to avoid). Plus the range in
column A will be changing (row numbers can change). Is
there are any other solution that will loop thru column A
as long as there is data and compare the data to the list
of invalid accounts (but this list should not be saved as
a rangge in the workbook). Can it be coded in the body of
the macro somehow?
-----Original Message-----
try this where b1:b3 has your list and a21:a37 has the

rows to delete

Sub DeleteRowsInList()
For Each c In [b1:b3]
With Columns(1)
For r = 37 To 21 Step -1
With .Cells(r, 1)
If .Value = c Then .EntireRow.Delete
End With
Next
End With
Next c
End Sub

--
Don Guillett
SalesAid Software

"nat" wrote in

message
...
Hello,
Please help me to write a code to accomplish the

following:
.I have a list of account numbers listed in column A
(starting from the second row or A2)
.I need the macro to go down the list (while there is
still data) and determine if the account numbers are

valid
(against the list of invalid account numbers)
.And if it finds the invalid account number it should
delete the entire row

Of course I can determine the invalid accounts by using
the VLookUp function and then manually delete the rows

but
it would be great if it can be down automatically (via
macro).

Please help and thank you in advance.




.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Code Needed - new user

try this where your list is stored in an array

mm = Array(1, 2, 4)
For Each c In mm

--
Don Guillett
SalesAid Software

wrote in message
...
This solution still requires to keep the list of values in
b1:b3 (which I'm trying to avoid). Plus the range in
column A will be changing (row numbers can change). Is
there are any other solution that will loop thru column A
as long as there is data and compare the data to the list
of invalid accounts (but this list should not be saved as
a rangge in the workbook). Can it be coded in the body of
the macro somehow?
-----Original Message-----
try this where b1:b3 has your list and a21:a37 has the

rows to delete

Sub DeleteRowsInList()
For Each c In [b1:b3]
With Columns(1)
For r = 37 To 21 Step -1
With .Cells(r, 1)
If .Value = c Then .EntireRow.Delete
End With
Next
End With
Next c
End Sub

--
Don Guillett
SalesAid Software

"nat" wrote in

message
...
Hello,
Please help me to write a code to accomplish the

following:
.I have a list of account numbers listed in column A
(starting from the second row or A2)
.I need the macro to go down the list (while there is
still data) and determine if the account numbers are

valid
(against the list of invalid account numbers)
.And if it finds the invalid account number it should
delete the entire row

Of course I can determine the invalid accounts by using
the VLookUp function and then manually delete the rows

but
it would be great if it can be down automatically (via
macro).

Please help and thank you in advance.




.



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
User Forms - Tips needed to get started Stee n Excel Discussion (Misc queries) 3 June 28th 08 10:38 PM
User Forms - Tip needed to get started Stee n Excel Discussion (Misc queries) 0 June 28th 08 08:26 PM
User-friendly lookup solutions needed Sally Excel Discussion (Misc queries) 3 September 26th 07 06:26 AM
user checklist formula needed XP Newbie Bob New Users to Excel 5 November 1st 05 10:38 AM
code needed ibo Excel Programming 0 July 29th 03 05:32 PM


All times are GMT +1. The time now is 04:45 PM.

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"