Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Column heading and then Delete entire column


Hi,

I am trying to find a column heading within a worksheet and then delete
the entirecolumn. The following line of code does this fine but the
column I am trying to 'find' will not always be present. When the
column is not present this line of code will debug and I would like to
write something better than an 'On error' statement to proceed with the
code. I've been trying to put it in some kind of IF statement but
without success:

..Rows(1).Find("Myvalue").EntireColumn.Delete

I'm sure this is pretty simple but I'm having one of those days. Any
help, as always, would be much appreciated.

Thanks,

Adrian


--
Kobayashi
------------------------------------------------------------------------
Kobayashi's Profile: http://www.excelforum.com/member.php...nfo&userid=871
View this thread: http://www.excelforum.com/showthread...hreadid=476777

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find Column heading and then Delete entire column

dim FoundCell as range
with activesheet.rows(1)
set foundcell = .cells.find(what:="myValue",.....)
end with

if foundcell is nothing then
'not found
else
foundcell.entirecolumn.delete
end if



Kobayashi wrote:

Hi,

I am trying to find a column heading within a worksheet and then delete
the entirecolumn. The following line of code does this fine but the
column I am trying to 'find' will not always be present. When the
column is not present this line of code will debug and I would like to
write something better than an 'On error' statement to proceed with the
code. I've been trying to put it in some kind of IF statement but
without success:

Rows(1).Find("Myvalue").EntireColumn.Delete

I'm sure this is pretty simple but I'm having one of those days. Any
help, as always, would be much appreciated.

Thanks,

Adrian

--
Kobayashi
------------------------------------------------------------------------
Kobayashi's Profile: http://www.excelforum.com/member.php...nfo&userid=871
View this thread: http://www.excelforum.com/showthread...hreadid=476777


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Column heading and then Delete entire column


Dave,

Many thanks indeed! Works a treat, although I didn't want the code t
execute anything should the value not be found so I took the liberty o
amending your code to:

If FoundCell Is Nothing Then
'not found
Else
FoundCell.EntireColumn.Delete
End If

to

If Not FoundCell Is Nothing Then
FoundCell.EntireColumn.Delete
End If

Many thanks again!

Best Regards,

Adria

--
Kobayash
-----------------------------------------------------------------------
Kobayashi's Profile: http://www.excelforum.com/member.php...info&userid=87
View this thread: http://www.excelforum.com/showthread.php?threadid=47677

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Column heading and then Delete entire column


Forgot to add rating

--
Kobayash
-----------------------------------------------------------------------
Kobayashi's Profile: http://www.excelforum.com/member.php...info&userid=87
View this thread: http://www.excelforum.com/showthread.php?threadid=47677

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find Column heading and then Delete entire column

I bet if you try both versions, you won't notice a difference.



Kobayashi wrote:

Dave,

Many thanks indeed! Works a treat, although I didn't want the code to
execute anything should the value not be found so I took the liberty of
amending your code to:

If FoundCell Is Nothing Then
'not found
Else
FoundCell.EntireColumn.Delete
End If

to

If Not FoundCell Is Nothing Then
FoundCell.EntireColumn.Delete
End If

Many thanks again!

Best Regards,

Adrian

--
Kobayashi
------------------------------------------------------------------------
Kobayashi's Profile: http://www.excelforum.com/member.php...nfo&userid=871
View this thread: http://www.excelforum.com/showthread...hreadid=476777


--

Dave Peterson
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
To find the column with its column heading pol Excel Discussion (Misc queries) 8 October 15th 08 05:12 PM
delete column heading for print Daffy Excel Worksheet Functions 1 December 10th 05 07:37 PM
Entire Column Delete ermeko Excel Programming 3 April 28th 05 02:17 PM
Need Macro to Find Column Heading -- if none, then insert new column Jeff[_43_] Excel Programming 0 December 15th 04 07:08 AM
Test for Heading, Delete Column jmdaniel Excel Programming 3 September 15th 04 06:33 AM


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