Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default use Select Case with 'external' list

I am trying to write a macro that will delete all of the rows in a
report that contain names that are not on a list. Part of the problem
is that the macro can't be in the report and I want to store the list
of acceptable names in the workbook that contains the macro so they
can be easily updated. I have been trying to use Select Case but I
can't figure out how to access the list. I have tried using a Range To
Range but that just selected all the names from Andy to Walter. I was
thinking about using an array but I couldn't get my mind wrapped
around that.

The report workbook and the sheet the report is on could be named
anything so I'm going to have to rely on giving that sheet the focus.
The column with the tech's names could be anywhere but I have coded
for that thanks to snippets found in this group. The number of techs
could change and the length of the report itself will change every
time it is generated. Again, coded for thanks to the group.

Here is the code as it stands. I don't have anything in the Case at
the moment because that's where my mental block is:

The list on Sheet1, starting at A1, would be something like;
Tech Names (Header)
Andy
Fred
Penny
Tina
Walter
(A row with any other name should get deleted.)

Option Explicit
Sub Delete_other_names()

Dim LastRow As Long, r As Long, c1 As Long, LastName As Long
Dim Rng As Range, Tx As String, Ts As String
Dim header As String, n As Long
Dim src As Worksheet

Set src = ThisWorkbook.Worksheets(1) 'MyTechs.xls/Sheet1

' Find last name on Tech list.
LastName = src.Cells(Rows.Count, "A").End(xlUp).Row
' Find last row on the actual report.
LastRow = Cells(Rows.Count, "A").End(xlUp).Row

' Find which column of the report has the Tech's name.
header = "Assigned To"
Set Rng = ActiveSheet.Range("1:1").Find(What:=header, _
After:=Range("A1"), LookIn:=xlFormulas,
LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False)
If Not Rng Is Nothing Then c1 = Rng.Column

'Loop through entire report to find your techs.
For r = LastRow To 2 Step -1 'starts at the bottom to avoid
skipping lines.
Tx = Cells(r, c1).Value 'match this string.
Select Case Tx
Case "Help me, please"
Cells(r, 1).Interior.ColorIndex = 0 'essentially, do
nothing.
Case Else
ActiveSheet.Rows(r).EntireRow.Delete
End Select
Next r

End Sub

The other thought I have is that I am doing the checking and deleting
backwards, meaning if it's on the list do nothing otherwise delete the
row. Let me know what a more logical way to do that is.

Thanks in advance.
Bill

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
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
import external data sql case statement burkecrosby Excel Discussion (Misc queries) 0 January 25th 07 04:26 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
Pivot Tables, can I use an external list to select data items? Brian Lofquist Excel Worksheet Functions 0 January 4th 05 06:43 PM


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