Sign in to follow this  
Followers 0
iamtheky

Excel Conditional Formatting

3 posts in this topic

#1 ·  Posted (edited)

The below writes a 2d array to an excel sheet, then colors the font of those items in column B with values less than 60. i have these remaining issues:

1) select the entire row when the condition is met, and color the font of the entire row red

2) select the entire contents of column "B" to be conditionally formatted without having to specify row count

and help would be greatly appreciated

#include<excel.au3>

Local $DaysLeft[5][2] = [["LocoDarwin", 59],["Jon", 200],["big_daddy", 3000],["DaleHolm", -4],["GaryFrost", 50]]


$oExcel = _ExcelBookNew(0) ;Create new book, make it visible
_ExcelWriteSheetFromArray($oExcel, $DaysLeft, 1, 1, 0, 0) ;0-Base Array parameters

Global Const $xlCellValue = 1
Global Const $xlless = 6

With $oExcel
.Range("B1:B150").Select
.Selection.FormatConditions.Delete ;Delete Existing FormatConditions
.Selection.FormatConditions.Add($xlCellValue, $xlLess, "60") ;FormatConditions(1)
EndWith

With $oExcel.Selection.FormatConditions(1)
.Font.Bold = True
.Font.Italic = False
.Font.ColorIndex = 3 ;Red
EndWith

_ExcelBookSaveAs($oExcel, @ScriptDir & "" & @Year & @MON & @MDAY & "_daysremaining.xls", "xls", 0, 1) ; Now we save it into the temp directory; overwrite existing file if necessary
_ExcelBookClose($oExcel) ; And finally we close
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites



$oRange = $oExcel.ActiveCell.EntireColumn

.EntireColumn is the way to go.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

works for the column range. Thanks.

--I have gone another route now that seems to suffice

#include<excel.au3>

Local $DaysLeft[5][2] = [["LocoDarwin", 59],["Jon", 200],["big_daddy", 3000],["DaleHolm", -4],["GaryFrost", 50]]

$oExcel = _ExcelBookNew(0) ;Create new book, make it visible
_ExcelWriteSheetFromArray($oExcel, $DaysLeft, 1, 1, 0, 0) ;0-Base Array parameters

For $i = 1 to 999
$cell = _ExcelReadCell ($oExcel , $i , 2)
If $cell = "" Then ExitLoop
If $cell < "60" Then
$oExcel.range("A" & $i & ":B" & $i).select
$oExcel.selection.Font.ColorIndex = 3
$oExcel.selection.Font.Bold = True
endif
next

_ExcelBookSaveAs($oExcel, @ScriptDir & "" & @Year & @MON & @MDAY & "_daysremaining.xls", "xls", 0, 1) ; Now we save it into the temp directory; overwrite existing file if necessary
_ExcelBookClose($oExcel) ; And finally we close
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question about Excel, i have to create several charts one below the other dynamically.
      I have thought to use:
       
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count  
      And then to use it in this way:
      $Graph_position = "=Test1!A"&$iRowCount+2&":K"&$iRowCount+24 But it doesn't work with charts.
      Does anyone have a suggestion?
       
    • LoneWolf_2106
      By LoneWolf_2106
      Hi all,
      i have an empty csv file, i have a non formatted text file.
      What do i want to do?
      I want to automate the process "get external data" in Excel, i want to import the data from the text file and basically create a csv file with a specific character encoding.
      Is it possible with AutoIT?
       
    • breakbadsp
      By breakbadsp
      I  want to create a excel file from my script if it does not exist.
      _ExcelBookOpen throws error=2 if file does not exist, after this error i want to create new file at this point.
      can i use _FileCreate()?
      _Logger($sLogPath, "{INFO}------: Opening Excel File: " & $sExcelPath& "") While 1 Local $oExcelTestResult = _ExcelBookOpen($sExcelPath) If @error = 2 Then If not _FileCreate($sResExcelPath) Then MsgBox(0, "Error", "Error In Opening REsult Excel File: Error: " & String(@error)) _Logger($sLogPath, "{ERROR}------: Result Excel File does not exist.. tried to create new but :ERROR : " & String(@error) & "") ExitLoop Else _Logger($sLogPath, "{INFO}------: Result Excel File does not exist.. **Created New**: ") EndIf Else ExitLoop EndIf WEnd  
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have to store an entire row of a Excel workbook into an array.  The row index is stored in a variable.
      How can i do it?
      Thanks in advance for your support.