PC Review


Reply
Thread Tools Rate Thread

Compile error on range...

 
 
Sam
Guest
Posts: n/a
 
      19th May 2006
I get a compile error on line 21 below. What is wrong with it?
I am trying to color fill a cell based on the XColor value...
Help!


0 r = 1
1 Do While ActiveSheet.Cells(r, 1) <> ""
2 str1 = ActiveSheet.Cells(r, 1)
3 str2 = ActiveSheet.Cells(r, 2)
4 comp1 = strip(str1)
5 comp2 = strip(str2)
6
7 If (comp1 <> comp2) Then
8 XColor = 5
9 Else
10 XColor = 25
11 End If
12
13 If (XColor) Then
14 Range("ActiveSheet.Cells(r, 1):ActiveSheet.Cells(r, 2)").Select
15 With Selection.Interior
16 .ColorIndex = 3
17 .Pattern = xlSolid
18 End With
19 End If
20 r = r + 1
21 Loop

 
Reply With Quote
 
 
 
 
Sam
Guest
Posts: n/a
 
      19th May 2006
Sorry - I meant on line 14!
> 0 r = 1
> 1 Do While ActiveSheet.Cells(r, 1) <> ""
> 2 str1 = ActiveSheet.Cells(r, 1)
> 3 str2 = ActiveSheet.Cells(r, 2)
> 4 comp1 = strip(str1)
> 5 comp2 = strip(str2)
> 6
> 7 If (comp1 <> comp2) Then
> 8 XColor = 5
> 9 Else
> 10 XColor = 25
> 11 End If
> 12
> 13 If (XColor) Then
> 14 Range("ActiveSheet.Cells(r, 1):ActiveSheet.Cells(r, 2)").Select
> 15 With Selection.Interior
> 16 .ColorIndex = XColor
> 17 .Pattern = xlSolid
> 18 End With
> 19 End If
> 20 r = r + 1
> 21 Loop


 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      19th May 2006
Change it to

Range(ActiveSheet.Cells(R, 1), ActiveSheet.Cells(R, 2)).Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sorry - I meant on line 14!
>> 0 r = 1
>> 1 Do While ActiveSheet.Cells(r, 1) <> ""
>> 2 str1 = ActiveSheet.Cells(r, 1)
>> 3 str2 = ActiveSheet.Cells(r, 2)
>> 4 comp1 = strip(str1)
>> 5 comp2 = strip(str2)
>> 6
>> 7 If (comp1 <> comp2) Then
>> 8 XColor = 5
>> 9 Else
>> 10 XColor = 25
>> 11 End If
>> 12
>> 13 If (XColor) Then
>> 14 Range("ActiveSheet.Cells(r, 1):ActiveSheet.Cells(r,
>> 2)").Select
>> 15 With Selection.Interior
>> 16 .ColorIndex = XColor
>> 17 .Pattern = xlSolid
>> 18 End With
>> 19 End If
>> 20 r = r + 1
>> 21 Loop

>



 
Reply With Quote
 
Sam
Guest
Posts: n/a
 
      19th May 2006
That did the trick. Thank you.
May I impose with one more sudggestion?
In line 1, where I control the looping, I am not happy with check for
spaces, because someone could have added a space accidentally. Is there
a better way to loop until the end of all data?
Again, thanks!

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th May 2006
Do While trim(ActiveSheet.Cells(r, 1)) <> ""

???

Sam wrote:
>
> I get a compile error on line 21 below. What is wrong with it?
> I am trying to color fill a cell based on the XColor value...
> Help!
>
> 0 r = 1
> 1 Do While ActiveSheet.Cells(r, 1) <> ""
> 2 str1 = ActiveSheet.Cells(r, 1)
> 3 str2 = ActiveSheet.Cells(r, 2)
> 4 comp1 = strip(str1)
> 5 comp2 = strip(str2)
> 6
> 7 If (comp1 <> comp2) Then
> 8 XColor = 5
> 9 Else
> 10 XColor = 25
> 11 End If
> 12
> 13 If (XColor) Then
> 14 Range("ActiveSheet.Cells(r, 1):ActiveSheet.Cells(r, 2)").Select
> 15 With Selection.Interior
> 16 .ColorIndex = 3
> 17 .Pattern = xlSolid
> 18 End With
> 19 End If
> 20 r = r + 1
> 21 Loop


--

Dave Peterson
 
Reply With Quote
 
Sam
Guest
Posts: n/a
 
      21st May 2006
thank you

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export report to Excel, Error message "Compile Error: Argument not mc Microsoft Access External Data 0 16th Jul 2009 09:11 PM
defining a range compile error =?Utf-8?B?SmFuaXM=?= Microsoft Excel Programming 1 30th Aug 2006 02:59 AM
VBAProject name compile error, not defined at compile time Matthew Dodds Microsoft Excel Programming 1 13th Dec 2005 07:17 PM
When I start XL I get error message "Compile error in Hidden Modu. =?Utf-8?B?QWxleCBPYWtlcw==?= Microsoft Excel Crashes 1 22nd Feb 2005 07:29 PM
error message in Winword. ( Compile error in hidden module: AutoE. =?Utf-8?B?TXkgRXJyb3IgUHJvYmxlbQ==?= Microsoft Access Getting Started 1 4th Oct 2004 02:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:11 PM.