Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default If command with 3 options

I am trying to compare a row of names with a column list.
If the name is in the list I want it to go to the next cell.
If the name = NULL then I want it to go to the next cell.
If the name = Total I want it to stop.
If the name is not in the list I want it to delete the column.

Sub NameDelete()

With Sheets("RowOfNames")
For Each cell In .Range("$1:$1")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Sheets("List").Range("$A:$A"), 0)
On Error GoTo 0
If cell.Value = Null Then Resume Next
If cell.Value = "Total" Then End
If cell.Value < iRow Then cell.EntireColumn.Delete
Next cell
End With
End Sub

It runs, but deletes everything.

I copied this code from another answer and tried to adopt it to my project.

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default If command with 3 options

After learning how to use the debug to see my what the variables are set too
and stepping through it, the problem seems to be with:

iRow = Application.Match(cell.Value, Sheets("List").Range("$A:$A"), 0)

iRow never changes from equaling 0, so it just deletes every column. The
NULL and "Total" arguments seem to work fine.

"Kevin Porter" wrote:

I am trying to compare a row of names with a column list.
If the name is in the list I want it to go to the next cell.
If the name = NULL then I want it to go to the next cell.
If the name = Total I want it to stop.
If the name is not in the list I want it to delete the column.

Sub NameDelete()

With Sheets("RowOfNames")
For Each cell In .Range("$1:$1")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Sheets("List").Range("$A:$A"), 0)
On Error GoTo 0
If cell.Value = Null Then Resume Next
If cell.Value = "Total" Then End
If cell.Value < iRow Then cell.EntireColumn.Delete
Next cell
End With
End Sub

It runs, but deletes everything.

I copied this code from another answer and tried to adopt it to my project.

Thanks 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
command line options/switches to print excel file Stranger[_2_] Excel Discussion (Misc queries) 1 March 17th 09 01:04 PM
Print command options scarrigan Excel Discussion (Misc queries) 1 October 20th 08 08:42 PM
further options following a command button click thesaxonuk Excel Discussion (Misc queries) 0 October 23rd 06 01:46 PM
Excel Command Line Options mr tom Excel Programming 3 September 7th 05 04:31 PM
Command line options R Avery Excel Programming 4 October 21st 04 10:10 PM


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