My code (below) is giving me an "End if without block if" Error.
I'm trying to highlight a row in a table according to the first cell. Can anyone help me? - Sub colorrowcellone()
-
With aTable
-
For r = 2 To .Rows.Count
-
If .Cell(r, 1).Range.Text <> "W5" Then colorit = Not colorit
-
End If
-
'then determine color to use on this row, light green or no shading
-
If colorit Then
-
Color = RBG(255, 255, 255)
-
Else
-
Color = RBG(220, 230, 241)
-
End If
-
.Rows(r).Shading.BackgroundPatternColor = Color
-
Next r
-
End With
-
End Sub
Here is your code with the required code tags: - Sub colorrowcellone()
-
With aTable
-
For r = 2 To .Rows.Count
-
If .Cell(r, 1).Range.Text <> "W5" Then colorit = Not colorit
-
End If
-
'then determine color to use on this row, light green or no shading
-
If colorit Then
-
Color = RBG(255, 255, 255)
-
Else
-
Color = RBG(220, 230, 241)
-
End If
-
.Rows(r).Shading.BackgroundPatternColor = Color
-
Next r
-
End With
-
End Sub
Because you have the THEN action in line 4 on the same line as the IF, you don't need the End If on line 5. So you need to do either - If .Cell(r, 1).Range.Text <> "W5" Then
-
colorit = Not colorit
-
End If
Or remove line 5.
I would also highly recommend using indentation to make your code easier to read. For example, - Sub colorrowcellone()
-
With aTable
-
For r = 2 To .Rows.Count
-
If .Cell(r, 1).Range.Text <> "W5" Then
-
colorit = Not colorit
-
End If
-
-
'then determine color to use on this row, light green or no shading
-
If colorit Then
-
Color = RBG(255, 255, 255)
-
Else
-
Color = RBG(220, 230, 241)
-
End If
-
-
.Rows(r).Shading.BackgroundPatternColor = Color
-
Next r
-
End With
-
End Sub
1 1597
Here is your code with the required code tags: - Sub colorrowcellone()
-
With aTable
-
For r = 2 To .Rows.Count
-
If .Cell(r, 1).Range.Text <> "W5" Then colorit = Not colorit
-
End If
-
'then determine color to use on this row, light green or no shading
-
If colorit Then
-
Color = RBG(255, 255, 255)
-
Else
-
Color = RBG(220, 230, 241)
-
End If
-
.Rows(r).Shading.BackgroundPatternColor = Color
-
Next r
-
End With
-
End Sub
Because you have the THEN action in line 4 on the same line as the IF, you don't need the End If on line 5. So you need to do either - If .Cell(r, 1).Range.Text <> "W5" Then
-
colorit = Not colorit
-
End If
Or remove line 5.
I would also highly recommend using indentation to make your code easier to read. For example, - Sub colorrowcellone()
-
With aTable
-
For r = 2 To .Rows.Count
-
If .Cell(r, 1).Range.Text <> "W5" Then
-
colorit = Not colorit
-
End If
-
-
'then determine color to use on this row, light green or no shading
-
If colorit Then
-
Color = RBG(255, 255, 255)
-
Else
-
Color = RBG(220, 230, 241)
-
End If
-
-
.Rows(r).Shading.BackgroundPatternColor = Color
-
Next r
-
End With
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tom |
last post by:
Suppose you have code structure like this:
Option Explicit
Dim MyVariable As Single
Private Sub CallingProcedure()
Call CalledProcedure()
....Do This ...
End Sub
Private Sub...
|
by: Thelma Lubkin |
last post by:
I use code extensively; I probably overuse it. But I've been using
error trapping very sparingly, and now I've been trapped by that.
A form that works for me on the system I'm using, apparently...
|
by: JPARKER |
last post by:
Our DB2 8.2 FixPak9 database running on Win2K crashed with after
reporting this message
SQL0902C A system error (reason code = 9") ocurred
I have searched the DB2 documentation as well as the...
|
by: Daylor |
last post by:
hi.
i want to destroy the application when i catch some exception.
i have multithread app.
how can i destroy the application and exit immedietly ?
|
by: lambu76 |
last post by:
Hi all,
I've this strange problem.
I've deployed a big and complicated ASP web application on different
web server, all of them installed with Win 2000 Advanced Server SP3.
I'm completly sure...
|
by: globomike |
last post by:
Hi,
can anybody tell me what the reason code 18 means in combination with
a SQL0902 error?
It would be helpful to know details about the reason code but I could
not find any details about that...
|
by: pelicanstuff |
last post by:
Hi - Was wondering if anybody could tell me why this rather crappy code is giving me an 'Else without If' error on compile?
All the Elses and Ifs look ok to me but there's a few.
Private Sub...
|
by: madhavi patel |
last post by:
what should i do id complie error shows endif without block if?
|
by: devarts |
last post by:
I'm getting an "End if without Block if" error with the following code:
Private Sub Command42_Click()
Dim ctl As Control
Dim strTag As String
Dim intCtr As Integer
Dim strBuild As String
Do...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |