Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Conflict Between Two Add-Ins | Excel Programming | |||
Name conflict | Excel Discussion (Misc queries) | |||
Name Conflict | Excel Discussion (Misc queries) | |||
Name Conflict | Excel Discussion (Misc queries) | |||
Conflict | Excel Programming |