VBA ActiveCell location to start Conditional Formatting

jjlafond

Board Regular
Joined
Jul 17, 2014
Messages
56
Hello,

I am trying to apply Conditional formatting using VBA from an active cell location. I can't get it working no matter what I do.

I think I've narrowed down the problem to the bolded parts. If I have an actual cell address (C19) I can get it to work for a range starting with C19.

I need to be able to run the Conditional Format as part of a Sub. I have ActiveCell locations but the operator at the screen does not know the location to start.

This is what I have at the moment:


startCell = ActiveCell.Address(0, 0)
MsgBox startCell


ActiveCell.Resize(6, NumCavLines).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND(LEN(TRIM(startCell))>0,OR(startCell>$L$6,startCell<$M$6))"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Not that you need a new thread for this question...but:

Code:
[COLOR=#333333]startCell = ActiveCell.Address(0, 0)[/COLOR]

Doesn't exist. The syntax is (ROW, COLUMN) which is the formula I gave you in the other post you made. Remove the (0,0) and try again. That will always return NULL.
 
Upvote 0
It is a more specific problem, so I started a new thread for it.

startCell = ActiveCell.Address(0, 0)
MsgBox startCell
Does work and returns C19 as the value in the MsgBox.

But it doesn't in Conditional Formatting either. You gave me code for cells before, and it didn't work. I thought that since the recorded macro had range values (C19), maybe startCell value as a range would work. It also failed, no errors, but no formatting either.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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