#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default Conflict

I have a conflict in VBA
-------------------------------------
Sub sequence11()
With Sheets("Sheet2")
x5 = Range("J1").Value
x6 = Range("J2").Value
Set x = .Range("B" & x6 & ":G" & x5)
End With

For Each c In x
If c.Value = (c.Offset(0, 1).Value - 1) Then
Range(c, c.Offset(0, 1)).Select
With Selection.Interior
..Color = RGB(255, 204, 153) '222, 222, 222 Gray
..Pattern = xlSolid
End With
End If
Next
Range("A1").Select
End Sub
'---------------------------------------------------
Sub bonussequence()
With Sheets("Sheet2")
Set x = .Range(.Range("K2"), .Range("N31"))
End With
For Each c In x
If c.Value = (c.Offset(0, 1).Value - 1) Then
Range(c, c.Offset(0, 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
End If
Next
Range("A1").Select
End Sub
'----------------------------------------------------

The last macro will not finish

Both are used on the same sheet,
Both have different objects,or GUI

When tried separately on different worksheets, they work
Any suggestions, I would like to have them work indepent,
on same worksheet.

With Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Conflict

Hi,

Am Thu, 1 Jan 2015 19:04:47 -0800 (PST) schrieb smandula:

The last macro will not finish


try:

Sub bonussequence()
With Sheets("Sheet2")
Set x = .Range("K2:N31")
For Each c In x
If c = c.Offset(0, 1) - 1 Then
c.Resize(, 2).Interior.ColorIndex = 40
End If
Next
End With
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default Conflict

On Thursday, January 1, 2015 10:04:56 PM UTC-5, smandula wrote:
I have a conflict in VBA
-------------------------------------
Sub sequence11()
With Sheets("Sheet2")
x5 = Range("J1").Value
x6 = Range("J2").Value
Set x = .Range("B" & x6 & ":G" & x5)
End With

For Each c In x
If c.Value = (c.Offset(0, 1).Value - 1) Then
Range(c, c.Offset(0, 1)).Select
With Selection.Interior
.Color = RGB(255, 204, 153) '222, 222, 222 Gray
.Pattern = xlSolid
End With
End If
Next
Range("A1").Select
End Sub
'---------------------------------------------------
Sub bonussequence()
With Sheets("Sheet2")
Set x = .Range(.Range("K2"), .Range("N31"))
End With
For Each c In x
If c.Value = (c.Offset(0, 1).Value - 1) Then
Range(c, c.Offset(0, 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
End If
Next
Range("A1").Select
End Sub
'----------------------------------------------------

The last macro will not finish

Both are used on the same sheet,
Both have different objects,or GUI

When tried separately on different worksheets, they work
Any suggestions, I would like to have them work indepent,
on same worksheet.

With Thanks


Thanks Claus,
Your solution works by itself
However,when used on Sheet 2, the macro stops midway in rqange.

The error report is

run time error '13'
Type mismatch

I don't know what the problem is?

With Thanks
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Conflict

For me, the original code fails on any sheet other than Sheet2, because of the Select step. It only works ActiveSheet, otherwise giving
Run-time error '1004'
Select method of Range class failed.

Claus's method of c.property = xxx should work regardless of which sheet is active.

What is c.address, c.value, and c.offset(0,1).value when the error occurs?

Carl.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Conflict

For me, the original code fails on any sheet other than Sheet2,
because of the Select step. It only works ActiveSheet, otherwise
giving
Run-time error '1004'
Select method of Range class failed.


It only works for "Sheet2" because it's hard-coded to only work on
"Sheet2"!!!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Conflict

Hi,

Am Fri, 2 Jan 2015 18:26:41 -0800 (PST) schrieb smandula:

Type mismatch


how did you declare the variables?
Dim x As Range, c As Range


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Conflict

Hi again,

Am Sat, 3 Jan 2015 17:14:12 +0100 schrieb Claus Busch:

how did you declare the variables?
Dim x As Range, c As Range


if in c.offset(,1) is text then you get the mismatch error.
Try:
Sub bonussequence()
Dim x As Range, c As Range

With Sheets("Sheet2")
Set x = .Range("K2:N31")
For Each c In x
If IsNumeric(c.Offset(, 1)) Then
If c = c.Offset(0, 1) - 1 Then
c.Resize(, 2).Interior.ColorIndex = 40
End If
End If
Next
End With
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Conflict

Went for a walk, thought of the problem. The comparison for the right-most column is to a cell outside the range, which contains a value which fails the compare. Claus's IsNumeric check is one way to handle it, another is to restrict the checks to not include the right-most column.
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default Conflict

On Thursday, January 1, 2015 10:04:56 PM UTC-5, smandula wrote:
I have a conflict in VBA
-------------------------------------
Sub sequence11()
With Sheets("Sheet2")
x5 = Range("J1").Value
x6 = Range("J2").Value
Set x = .Range("B" & x6 & ":G" & x5)
End With

For Each c In x
If c.Value = (c.Offset(0, 1).Value - 1) Then
Range(c, c.Offset(0, 1)).Select
With Selection.Interior
.Color = RGB(255, 204, 153) '222, 222, 222 Gray
.Pattern = xlSolid
End With
End If
Next
Range("A1").Select
End Sub
'---------------------------------------------------
Sub bonussequence()
With Sheets("Sheet2")
Set x = .Range(.Range("K2"), .Range("N31"))
End With
For Each c In x
If c.Value = (c.Offset(0, 1).Value - 1) Then
Range(c, c.Offset(0, 1)).Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
End If
Next
Range("A1").Select
End Sub
'----------------------------------------------------

The last macro will not finish

Both are used on the same sheet,
Both have different objects,or GUI

When tried separately on different worksheets, they work
Any suggestions, I would like to have them work indepent,
on same worksheet.

With Thanks


Many, Many Thanks Claus

The solution works perfectly.
Thanks for reply, and especially
your solution.
I couldn't do it.

Bye for Now

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
Conflict Between Two Add-Ins jeremiah adams Excel Programming 1 November 21st 08 09:03 PM
Name conflict smaruzzi Excel Discussion (Misc queries) 3 October 4th 08 01:44 PM
Name Conflict Roger[_4_] Excel Discussion (Misc queries) 2 March 15th 08 01:13 AM
Name Conflict Roger[_4_] Excel Discussion (Misc queries) 5 March 14th 08 02:14 PM
Conflict MathewPBennett Excel Programming 3 December 22nd 03 09:29 PM


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