Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to stop at the lastrow 1

Status
Not open for further replies.

coltaalex

Technical User
Jul 2, 2010
61
0
0
US
how to stop at the last row selection "R11C14:R10000C14"
I have a sheet where i have a column with data, number of row every time is different, some time i have less data some times more,
how can i stop my conditional formatting at the last row of data
every time the code is going until 10000, but some time i have just 5000 line, so how can i stop it at 5000
the code bellow is for conditional formatting:



Sub Check_Energy_Codes()

Application.Goto Reference:="R11C16:R10000C16"

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=COUNTIF(Hours,P11)=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
 


hi,
Code:
Sub Check_Energy_Codes()
    
    With Cells(11, 16).CurrentRegion
        .FormatConditions.Add _
            Type:=xlExpression, _
            Formula1:="=COUNTIF(Hours,P11)=0"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 255
            .TintAndShade = 0
        End With
        .FormatConditions(1).StopIfTrue = False
    End With
End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip can you please explain me how your code is stopping the conditional formatting ?
Sorry for disturbing you so much ,
what condition did you use to stop the code ?
 


What verion of Excel please?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 

Right click in the ribbon and select Customize quick acess toolbar (QAT)

Choose commands from All Commands

scroll to Select Current Region and ADD to your QAT.

OK

Now select P11 on your sheet.

Hit the Select Current Region tool icon you just added to your QAT.

Observe what is selected.





Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


All 1,048,576 rows and 16,384 columns?



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


Do you actually have DATA in every cell on the sheet?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
i have data just in the first 2 cells, and in the cell 4, so CF suppose to color the cells 1 and 2, ad stop at 3, because 3 is empty,
now it is coloring also the 4 cells.
Here is my full code, it has tow CF rules, first is checking the duplicates numbers , and second one is coloring in white the empty cells :

Sub Check_Energy_Codes()

Application.Goto Reference:="R11C14:R10000C14"

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=COUNTIF(Rates,N11)=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=LEN(TRIM(N11))=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
End With
Selection.FormatConditions(1).StopIfTrue = False

Dim N As Long, i As Long

i = 0
For N = 11 To 10000
If Cells(N, 14) <> "" Then
i = i + (Application.CountIf(Range("Rates"), Cells(N, 14)) = 0)
End If
Next N
If i <> 0 Then
MsgBox "Check Energy Rate Codes"
End If

End Sub
 

i have data just in the first 2 cells, and in the cell 4, so CF suppose to color the cells 1 and 2, ad stop at 3, because 3 is empty,
THAT is NOT what your code tells me!!!
Code:
Application.Goto Reference:="R11C16:R10000C16"
    
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
THAT says that your data started in ROW 11 COLUMN 16!!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
it the same code just the instead of 16 now is 14, because i have to use CF for several columns, but methodology is the same,
 


i have data just in the first 2 cells, and in the cell 4, so CF suppose to color the cells 1 and 2, ad stop at 3, because 3 is empty, now it is coloring also the 4 cells.
Please tell me EXACTLY what FORMULA you have in cell 3?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip i don't have any formula, in these cells,, i introduce by hand all the codes, the code is combination of some letters and numbers , like: CFT8-100
 



Is your concern that the CF is APPLIED to the 3rd cell, or is it that the FORMAT is not displaying as expected?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
my concern is that CF is applied to the 3 cell ,
it suppose to stop at the first empty cell
 


So it must stop at the first empty cell of WHAT COLUMN, starting in WHAT ROW?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
of column 14 Which is N , stating from row 11
 


And what columns do you want to have the CF applied to?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top