#1
|
||||
|
||||
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition
Hello Pros,
I'm pretty proud of myself, to figured out how to have Row 1 if the Font color is DarkRed, for example, to put Row(1) as Text. It works, I've tested it on tables with multiple rows, having DarkRed on Row 1 and other tables having it a blue for instance, on Row 1. And some single Table Row being either DarkRed and others being Blue. What I'm having an issue, is trying to find Font Color DarkRed AND Font being Bold. As you can see with the single quote, ' , which is considered Text (in VBA, it would show in Green), I'm just trying to show i've tried many ways, it didn't work. Code:
Sub TBL_to_Txt_if_Row1_is_DarkRed() Application.ScreenUpdating = False Dim aTbl As Table, aRow As Row Dim rg As range For Each aTbl In ActiveDocument.Tables With aTbl '.Rows(1).range.Font.Color = wdColorOrange / wdColorDarkRed '.Rows(1).range.Font.Color = 192 '.Rows(1).range.Rows.Select 'Selection.SplitTable 'End With 'If (aTbl.Rows(1).range.Font.Color = 192) + (aTbl.Rows(1).range.Font.Bold = True) Then 'If (aTbl.Rows(1).range.Font.Bold) + (aTbl.Rows(1).range.Font.ColorIndex = 192) = True Then If aTbl.Rows(1).range.Font.Color = 192 = True Then .Rows(1).ConvertToText Separator:=wdSeparateByParagraphs, _ NestedTables:=False Else End If End With Next Application.ScreenUpdating = True On Error GoTo 0 lbl_Exit: Exit Sub End Sub Thanking you in advance Cendrinne |
#2
|
||||
|
||||
Combining two conditions can be with an AND or an OR inclusion
If test1 = blah AND test2 = "blah blah" then 'this means both must be true If test1 = blah OR test2 = "blah blah" then 'this means one must be true So your code could be Code:
For Each aTbl In ActiveDocument.Tables With aTbl.Rows(1).Range.Font If .Color = 192 And .Bold = True Then aTbl.Rows(1).ConvertToText Separator:=wdSeparateByParagraphs, NestedTables:=False ElseIf .Color = 192 Then 'do something else End If End With Next aTbl
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
||||
|
||||
You need
Code:
If aTbl.Rows(1).Range.Font.Color = 192 And aTbl.Rows(1).Range.Font.Bold = True Then P.S.It appears Andrew and I were replying at the same time. Either will work.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#4
|
||||
|
||||
Wow it works wonderfully. I'm so excited :) Thank you
Quote:
This helped alot. I'm so grateful to have you guys from the forum. Thank you soooooooo very much, Andrew. I'm getting better, but still lots to learn. Cendrinne |
#5
|
||||
|
||||
Hello Graham, yes I've tested yours too, wonderful :) Works great too
Quote:
I'm so happy you wrote it that way too, cause I'm certain I was so close at one point. I kept getting error message or it just didn't do anything. I might have had a typo, cause I remember using And, and the long way vs the way Andrew wrote it. Both are great and I'm very greateful you help as well. Like I told Andrew, I'm getting better, but still lot's to learn. Thanks so much for guiging me, Graham. Cendrinne |
Tags |
2x conditional format, help please, rows(1) |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
sumProduct with OR condition | ShostyFan | Excel | 7 | 10-16-2019 02:19 PM |
If condition not working. | jhansrod | Word VBA | 8 | 06-15-2019 05:59 AM |
How to use if condition to for this ... | LearnerExcel | Excel | 1 | 12-19-2016 02:14 PM |
Use Two (concatenate) Fields If Condition Is Met (If... Then... Else) | SoonerLater | Mail Merge | 1 | 09-30-2015 05:40 PM |
check with condition | karti | Word | 2 | 03-15-2011 06:06 AM |