Need correction in code, little correction..

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
Need correction in code, little correction..
Error - Object doesn't support this property or method..
Code:
With Worksheets("Sheet1")
    For i = 3 To RowCnt1
    If .HorizontalAlignment = xlLeft Then[COLOR=#ff0000]............Getting an error on this[/COLOR]
    .Cells(i, 6).Interior.Color = vbRed
    End If
    Next i
End With
 
Last edited:
giving me an error - "sub or function not defined"
Code:
For i = 3 To RowCnt1
If IsText(Cells(i, 6)) = True Then
Cells(i, 6).Interior.Color = vbRed
Else
End If
Next i

SOLVED..... THIS WHAT I EXACTLY WANT...THANKS JOE & ALL MEMBERS..
 
Last edited:
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You are welcome.

Note that you could avoid the whole For/Next loop and make it dynamic by applying the Conditional Formatting via VBA code (essentially, that is what you are kind of doing here, recreating Conditional Formatting, but not making it dynamic). That code would look like this:
Code:
    Dim rng As Range
    Set rng = Range("F3:F" & RowCnt1)
    rng.FormatConditions.Add Type:=xlExpression, Formula1:="=ISTEXT(F3)"
    rng.FormatConditions(rng.FormatConditions.Count).SetFirstPriority
    With rng.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
While the code may not look any shorter, it is actually much more efficient because it doesn't use loops (loops are notoriously slow and inefficient, and if there are better alternatives to use, it is usually advised to do so).
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top