Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default A way to simplify this please

Can someone suggest a way to Simplify the following code.

If Cells(6, ccx) = Cells(3, 19) Or Cells(6, ccx) = Cells(3, 20) Or
Cells(6, ccx) = Cells(3, 21) Or Cells(6, ccx) = Cells(3, 22) Or
Cells(6, ccx) = Cells(3, 23) Or Cells(6, ccx) = Cells(3, 24) Or
Cells(6, ccx) = Cells(3, 25) Or Cells(6, ccx) = Cells(3, 26) Or
Cells(6, ccx) = Cells(3, 27) Then
Cells(6, ccx).ClearContents
End If

Thank you
Larry
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default A way to simplify this please

I assumed the range you are matching to is on Sheet3, so change as needed.
VBA can use some of excels worksheet functions, so I used the MATCH function.
If a numeric value is returned (versus the #N/A error) clear the contents of
the specified cell.

Sub macro2()
Dim rngMatch As Range

With Worksheets("Sheet3")
Set rngMatch = .Range(.Cells(3, 19), _
.Cells(3, 27))
End With

With Application
If IsNumeric(.Match(Cells(6, ccx), rngMatch, 0)) Then _
Cells(6, ccx).ClearContents
End With

End Sub


"Larry Empey" wrote:

Can someone suggest a way to Simplify the following code.

If Cells(6, ccx) = Cells(3, 19) Or Cells(6, ccx) = Cells(3, 20) Or
Cells(6, ccx) = Cells(3, 21) Or Cells(6, ccx) = Cells(3, 22) Or
Cells(6, ccx) = Cells(3, 23) Or Cells(6, ccx) = Cells(3, 24) Or
Cells(6, ccx) = Cells(3, 25) Or Cells(6, ccx) = Cells(3, 26) Or
Cells(6, ccx) = Cells(3, 27) Then
Cells(6, ccx).ClearContents
End If

Thank you
Larry

  #3   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default A way to simplify this please

From your initial code I see the range you are matching to is on the same
worksheet and that worksheet must be the active sheet so

With Worksheets("Sheet3")
Set rngMatch = .Range(.Cells(3, 19), _
.Cells(3, 27))
End With

could be changed to
Set rngMatch = Range(Cells(3, 19), Cells(3, 27))


"JMB" wrote:

I assumed the range you are matching to is on Sheet3, so change as needed.
VBA can use some of excels worksheet functions, so I used the MATCH function.
If a numeric value is returned (versus the #N/A error) clear the contents of
the specified cell.

Sub macro2()
Dim rngMatch As Range

With Worksheets("Sheet3")
Set rngMatch = .Range(.Cells(3, 19), _
.Cells(3, 27))
End With

With Application
If IsNumeric(.Match(Cells(6, ccx), rngMatch, 0)) Then _
Cells(6, ccx).ClearContents
End With

End Sub


"Larry Empey" wrote:

Can someone suggest a way to Simplify the following code.

If Cells(6, ccx) = Cells(3, 19) Or Cells(6, ccx) = Cells(3, 20) Or
Cells(6, ccx) = Cells(3, 21) Or Cells(6, ccx) = Cells(3, 22) Or
Cells(6, ccx) = Cells(3, 23) Or Cells(6, ccx) = Cells(3, 24) Or
Cells(6, ccx) = Cells(3, 25) Or Cells(6, ccx) = Cells(3, 26) Or
Cells(6, ccx) = Cells(3, 27) Then
Cells(6, ccx).ClearContents
End If

Thank you
Larry

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default A way to simplify this please

JMB

Thank you it works very well

Larry



On Wed, 28 Jun 2006 18:04:02 -0700, JMB
wrote:

From your initial code I see the range you are matching to is on the same
worksheet and that worksheet must be the active sheet so

With Worksheets("Sheet3")
Set rngMatch = .Range(.Cells(3, 19), _
.Cells(3, 27))
End With

could be changed to
Set rngMatch = Range(Cells(3, 19), Cells(3, 27))


"JMB" wrote:

I assumed the range you are matching to is on Sheet3, so change as needed.
VBA can use some of excels worksheet functions, so I used the MATCH function.
If a numeric value is returned (versus the #N/A error) clear the contents of
the specified cell.

Sub macro2()
Dim rngMatch As Range

With Worksheets("Sheet3")
Set rngMatch = .Range(.Cells(3, 19), _
.Cells(3, 27))
End With

With Application
If IsNumeric(.Match(Cells(6, ccx), rngMatch, 0)) Then _
Cells(6, ccx).ClearContents
End With

End Sub


"Larry Empey" wrote:

Can someone suggest a way to Simplify the following code.

If Cells(6, ccx) = Cells(3, 19) Or Cells(6, ccx) = Cells(3, 20) Or
Cells(6, ccx) = Cells(3, 21) Or Cells(6, ccx) = Cells(3, 22) Or
Cells(6, ccx) = Cells(3, 23) Or Cells(6, ccx) = Cells(3, 24) Or
Cells(6, ccx) = Cells(3, 25) Or Cells(6, ccx) = Cells(3, 26) Or
Cells(6, ccx) = Cells(3, 27) Then
Cells(6, ccx).ClearContents
End If

Thank you
Larry


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
I need to simplify this... j5b9721 Excel Worksheet Functions 5 July 23rd 09 09:03 AM
please help simplify acarril[_12_] Excel Programming 0 September 27th 04 07:45 PM
please help simplify acarril[_11_] Excel Programming 1 September 27th 04 04:45 PM
please help simplify acarril[_9_] Excel Programming 1 September 21st 04 05:36 PM
Simplify Josh[_7_] Excel Programming 4 January 9th 04 12:16 AM


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