You are here:

Excel/Excel VBA Change Conditional Format Line Weight: Follow-up

Advertisement


Question
QUESTION: Hi Damon,

RE: Excel VBA Change Conditional Format Line Weight: Follow-up

With reference to, your great solution dated 13 July 2015; would it be possible to have a version of the code using cell D5 as a trigger so that I can use it on other sheets that have different processes going on?  Once again, your assistance would be very much appreciated.

Thank you,
Sam

ANSWER: Hi again Sam,

Before providing a solution I want to make sure I don't make any unwarranted assumptions by asking a few questions.

1. Do we still have values in D5:AA5 that each must be equal to the value in the adjacent cell?  If so should the code only draw the borders between columns with differences when D5 changes?

2. Since D5 is the only "trigger" cell, if D5 becomes unequal to E5 because E5 changes the code should NOT draw a border because D5 was not changed.  Correct?

3. Do you want D5 to trigger if an overlapping multi-cell range is pasted into row 5 to the left of D5?  That is, are we back to just one cell being changed at a time?

Damon



---------- FOLLOW-UP ----------

QUESTION: Hi Damon,

Thank you for your assistance.

[Before providing a solution I want to make sure I don't make any unwarranted assumptions by asking a few questions.]

1. Do we still have values in D5:AA5 that each must be equal to the value in the adjacent cell?  If so should the code only draw the borders between columns with differences when D5 changes?

Yes - only draw the borders between columns with differences when D5 changes.

2. Since D5 is the only "trigger" cell, if D5 becomes unequal to E5 because E5 changes, the code should NOT draw a border because D5 was not changed.  Correct?

Yes correct.  

3. Do you want D5 to trigger if an overlapping multi-cell range is pasted into row 5 to the left of D5?  That is, are we back to just one cell being changed at a time?

Yes - D5 to trigger if an overlapping multi-cell range is pasted into row 5.

Confused to the left of D5?  Would that be C5?

N0 Could be just one cell or multiple cells being changed at a time.

Sam

Answer
Hi Sam,

Let me know if this is what you had in mind:

Private Sub Worksheet_Change(ByVal Target As Range)

  Dim TI      As Range
  Set TI = Intersect(Target, Range("D5"))
  
  If TI Is Nothing Then Exit Sub
  
  'Cell D5 has changed.  Check all cells in row 5
  
  Dim iCol     As Integer
  
  For iCol = 4 To 26    'Check columns D through Z
 
     With Range(Cells(2, iCol), Cells(109, iCol))
        If Cells(5, iCol) <> Cells(5, iCol + 1) Then
         .Borders(xlRight).Weight = xlMedium
        Else
         .Borders(xlRight).LineStyle = xlNone
        End If
     End With
     
  Next iCol
 
End Sub


Damon
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Damon Ostrander

Expertise

I have extensive experience with VBA programming in Excel 5 through Excel 2013. As a former aerospace engineer with a large aerospace corporation and consultant in a small defense technology services company, I have developed a wide range of applications in VBA, including simulations involving mixed-language programming, satellite orbit mechanics, graphics and animation, and real-time applications. I am interested in moderate to hard VBA-related questions only.

Experience

I have developed and taught several courses in Excel VBA programming and also VBA programming in Office 97, 2000, and 2007. I have developed a number of large technical applications in Excel VBA for use within the aerospace industry.

Education/Credentials
B.S. in Electrical Engineering and Computer Science, University of California, Berkeley.

©2016 About.com. All rights reserved.