Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8534397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:11:13+00:00 2026-06-11T10:11:13+00:00

I was trying to add conditional formats like this: If expression =($G5<>) then make

  • 0

I was trying to add conditional formats like this:

If expression =($G5<>"") then make set interior green, use this for $A$5:$H$25.

Tried this, worked fine, as expected, then tried to adapt this as VBA-Code with following code, which is working, but not as expected:

With ActiveSheet.UsedRange.Offset(1)
  .FormatConditions.Delete
  'set used row range to green interior color, if "Erledigt Datum" is not empty
  With .FormatConditions.Add(Type:=xlExpression, _
                             Formula1:="=($" & cstrDefaultProgressColumn & _
                                                      .row & "<>"""")")
        .Interior.ColorIndex = 4
      End With
End With

The Problem is, .row is providing the right row while in debug, however my added conditional-formula seems to be one or more rows off – depending on my solution for setting the row. So I am ending up with a conditional formatting, which has an offset to the row, which should have been formatted.

In the dialog it is then =($G6<>"") or G3 or G100310 or something like this. But not my desired G5.

Setting the row has to be dynamicall, because this is used to setup conditional formats on different worksheets, which can have their data starting at different rows.

I was suspecting my With arrangement, but it did not fix this problem.

edit: To be more specific, this is NOT a UsedRange problem, having the same trouble with this:

Dim rngData As Range
Set rngData = ActiveSheet.Range("A:H") 'ActiveSheet.UsedRange.Offset(1)

rngData.FormatConditions.Delete

With rngData.FormatConditions.Add(Type:=xlExpression, _
                                  Formula1:="=($" & cstrDefaultProgressColumn & _
                                                  1 & "<>"""")")
    .Interior.ColorIndex = 4
End With

My Data looks like this:

1 -> empty cells
2 -> empty cells
3 -> empty cells
4 -> TitleCols -> A;B;C;...;H
5 -> Data to TitleCols
. .
. .
. .
25

When I execute this edited code on Excel 2007 and lookup the formula in the conditional dialog it is =($G1048571<>"") – it should be =($G1<>""), then everything works fine.

Whats even more strange – this is an edited version of a fine working code, which used to add conditional formats for each row. But then I realized, that it’s possible to write an expression, which formats a whole row or parts of it – thought this would be adapted in a minute, and now this ^^

edit: Additional task informations

I use conditional formatting here, because this functions shall setup a table to react on user input. So, if properly setup and a user edits some cell in my conditionalized column of this tabel, the corresponding row will turn green for the used range of rows.

Now, because there might be rows before the main header-row and there might be a various number of data-columns, and also the targeted column may change, I do of course use some specific informations.

To keep them minimal, I do use NamedRanges to determine the correct offset and to determine the correct DefaultProgessColumn.

GetTitleRow is used to determine the header-row by NamedRange or header-contents.

With ActiveSheet.UsedRange.Offset(GetTitleRow(ActiveSheet.UsedRange) - _
                                ActiveSheet.UsedRange.Rows(1).row + 1)

Corrected my Formula1, because I found the construct before not well formed.

Formula1:="=(" & Cells(.row, _
           Range(strMatchCol1).Column).Address(RowAbsolute:=False) & _
           "<>"""")"

strMatchCol1 – is the name of a range.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:11:15+00:00Added an answer on June 11, 2026 at 10:11 am

    Got it, lol. Set the ActiveCell before doing the grunt work…

    ActiveSheet.Range("A1").Activate
    

    Excel is pulling its automagic range adjusting which is throwing off the formula when the FromatCondition is added.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make my Makefiles platform conditional with statements like: ifeq ($(UNAME),
I am using Oracle 11g client, with ODP.NET. I am trying to add conditional
I'm trying to add a conditional where only records that meet the condition are
I am trying to add some more conditional logic to my edit action by
Can someone please help me with this conditional field validation in CodeIgniter? Trying to
So i am trying to do this. Add new root element and wrap old
I'm trying to add conditional logic to determine if there's one regex match for
I'm trying to add some conditional open graph tags to my app, using current_page
How can I produce something like this with Linq? I'm trying to work something
I'm trying to use the if function (as opposed to one of the conditional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.