VBA formula to use active cell instead of "G5" / "=COUNTIF(Brands!A:A,G5)=0"

Knockoutpie

Board Regular
Joined
Sep 10, 2018
Messages
116
Office Version
  1. 365
Platform
  1. Windows
Hi All,

is there a way to adjust this to that the formula uses the active cell instead of G5?

The reason i'm doing this is because the brand column, or first cell under brand column, will always be in a different place.
I'm applying a conditional formatting rule so that if a brand is not found on the brand sheet in column A, it will highlight the cell which isn't found.


VBA Code:
    ' Select column based on "brand"
    Columns("G:G").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=COUNTIF(Brands!A:A,G5)=0" ' Can I change G5 to be active cell?
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I will use the following to select the data in which conditional formatting will be applied.

This will search for the word "brand" in row 3, go down 2 rows, and select that cell and the data to the bottom of the worksheet.

However this still does not resolve on how I can have a formula use an active cell instead of a specified cell.
VBA Code:
' Find Brand
Dim a1
Dim b2 As Range
For Each a1 In Split("Brand", "|")
    Set b2 = ActiveSheet.Rows(3).Find(a1, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    
    If Not b2 Is Nothing Then
        b2.Offset(2).Select
        Exit For
    End If
Next
   Range(Selection, Selection.End(xlDown)).Select
    Selection.Select
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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