Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete Cells Based on Range


Hi

Does anyone have any suggestions for a Macro that would delete a
entire row in Sheet 2 if the value in column A Sheet 2 is equal to an
cell within the range of B2 to B50 on Sheet 1.

Thanks for your help

--
STEVE
-----------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...nfo&userid=187
View this thread: http://www.excelforum.com/showthread.php?threadid=39060

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Delete Cells Based on Range

Do A MATCH

On Error Resume Next
ans =
Application.Match(Range("A2").Value,Worksheets("Sh eet1").Range("B2:B50"),0)
On Error Goto 0
If ans 0 Then
Rows(2).Delete
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"STEVEB" wrote in
message ...

Hi

Does anyone have any suggestions for a Macro that would delete an
entire row in Sheet 2 if the value in column A Sheet 2 is equal to any
cell within the range of B2 to B50 on Sheet 1.

Thanks for your help!


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile:

http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=390607



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete Cells Based on Range


Hi Bob,

Thanks for your help, I appreciate it!

I could not get the code to work. the problem is at:

If ans 0 Then

I am getting this error message:

Run-time error '13':
Type mismatch

Is it because I am using dates?

I have about 20 dates on Sheet 1 Range B2-B50.
On Sheet 2 in Column A I have about 175 dates (1 in each row)
I would like to delete the entire row of data if any date in column
Sheet 2 matches any of the dates in the range B2-B50 on Sheet 1.

Thanks again for your help

--
STEVE
-----------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...nfo&userid=187
View this thread: http://www.excelforum.com/showthread.php?threadid=39060

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete Cells Based on Range


ans = 0
On Error Resume Next
ans = Application.WorksheetFunction.Match( _
clng(Range("A2").Value),Worksheets("Sheet1").Range ("B2:B50"),0)
On Error Goto 0
If ans 0 Then
Rows(2).Delete
End If

This deletes Row 2 on the active sheet. what you want to delete is
ambiguous.

--
Regards,
tom Ogilvy


"STEVEB" wrote in
message ...

Hi Bob,

Thanks for your help, I appreciate it!

I could not get the code to work. the problem is at:

If ans 0 Then

I am getting this error message:

Run-time error '13':
Type mismatch

Is it because I am using dates?

I have about 20 dates on Sheet 1 Range B2-B50.
On Sheet 2 in Column A I have about 175 dates (1 in each row)
I would like to delete the entire row of data if any date in column A
Sheet 2 matches any of the dates in the range B2-B50 on Sheet 1.

Thanks again for your help.


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile:

http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=390607



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Delete Cells Based on Range

Declare it as a Long Steve.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"STEVEB" wrote in
message ...

Hi Bob,

Thanks for your help, I appreciate it!

I could not get the code to work. the problem is at:

If ans 0 Then

I am getting this error message:

Run-time error '13':
Type mismatch

Is it because I am using dates?

I have about 20 dates on Sheet 1 Range B2-B50.
On Sheet 2 in Column A I have about 175 dates (1 in each row)
I would like to delete the entire row of data if any date in column A
Sheet 2 matches any of the dates in the range B2-B50 on Sheet 1.

Thanks again for your help.


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile:

http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=390607





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete Cells Based on Range


Hi Tom,

Thanks for the input, I appreciate it! I am still not getting the code
to work properly.

For example:

Column A - Sheet 2 lists every date beginning 1/1/2005 through 7/31/05.
210 rows.

Column E - Sheet 1 lists about 20 dates(1/1/2005, 6/8/2005, 5/4/2005,
12/30/2005, etc.). The range is E2:E50 (Only E2:e21 has a date in it
this month, however, so months there are up to 50 dates)

What I would like is to run a Macro that would compare Column E - Sheet
1 to Column A - Sheet 2. If Column A - Sheet 2 has any date listed in
Column E - Sheet 1, I would like to delete the entire row in Column A
Sheet 2.

I hope this helps. Thanks again


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile: http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=390607

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete Cells Based on Range

Sub DeleteMatches()
dim rng as Range, rng1 as Range
Dim res as Variant, cell as Range
With Worksheets("Sheet1")
set rng = .Range(.Cells(2,"E"),.Cells(2,"E").End(xldown))
end With
for each cell in rng
With Worksheets("Sheet2")
set rng1 = .range(".Cells(2,1),.Cells(2,1).End(xldown))
End with
res = Application.Match(clng(cell),rng1,0)
if not iserror(res) then
rng1(res).EntireRow.Delete
end if
Next
End sub

--
Regards,
Tom Ogilvy



"STEVEB" wrote in
message ...

Hi Tom,

Thanks for the input, I appreciate it! I am still not getting the code
to work properly.

For example:

Column A - Sheet 2 lists every date beginning 1/1/2005 through 7/31/05.
210 rows.

Column E - Sheet 1 lists about 20 dates(1/1/2005, 6/8/2005, 5/4/2005,
12/30/2005, etc.). The range is E2:E50 (Only E2:e21 has a date in it
this month, however, so months there are up to 50 dates)

What I would like is to run a Macro that would compare Column E - Sheet
1 to Column A - Sheet 2. If Column A - Sheet 2 has any date listed in
Column E - Sheet 1, I would like to delete the entire row in Column A
Sheet 2.

I hope this helps. Thanks again


--
STEVEB
------------------------------------------------------------------------
STEVEB's Profile:

http://www.excelforum.com/member.php...fo&userid=1872
View this thread: http://www.excelforum.com/showthread...hreadid=390607



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
Summing a range of cells based on criteria in another range Jack Excel Worksheet Functions 2 November 5th 09 01:46 AM
Delete rows based upon a range of times farmboy Excel Discussion (Misc queries) 6 October 16th 09 05:02 PM
Can I automatically add or delete cells based on IF statements Mike in OH Excel Discussion (Misc queries) 3 September 29th 06 01:02 AM
Delete record(s) in other cells based on value of one cell. MPope Excel Discussion (Misc queries) 1 October 12th 05 06:57 PM
Count cells in one range based on parameters in another range dave roth Excel Worksheet Functions 2 March 29th 05 05:33 PM


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