Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-25-2021, 08:30 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Windows 10 Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Office 2019
Competent Performer
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default 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
Any insights would be soooooo appreciated.

Thanking you in advance

Cendrinne
Reply With Quote
  #2  
Old 09-25-2021, 11:25 PM
Guessed's Avatar
Guessed Guessed is offline Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Windows 10 Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 09-25-2021, 11:27 PM
gmayor's Avatar
gmayor gmayor is offline Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Windows 10 Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #4  
Old 09-26-2021, 12:27 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Windows 10 Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Office 2019
Competent Performer
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Wink Wow it works wonderfully. I'm so excited :) Thank you

Quote:
Originally Posted by Guessed View Post
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

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
Reply With Quote
  #5  
Old 09-26-2021, 12:40 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Windows 10 Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Office 2019
Competent Performer
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Red face Hello Graham, yes I've tested yours too, wonderful :) Works great too

Quote:
Originally Posted by gmayor View Post
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.

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
Reply With Quote
Reply

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
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition If condition not working. jhansrod Word VBA 8 06-15-2019 05:59 AM
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition How to use if condition to for this ... LearnerExcel Excel 1 12-19-2016 02:14 PM
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition Use Two (concatenate) Fields If Condition Is Met (If... Then... Else) SoonerLater Mail Merge 1 09-30-2015 05:40 PM
Help, IF with 2 Conditions, Then, Else, only works if I have 1 condition check with condition karti Word 2 03-15-2011 06:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft