Jump to content

Help with hiding columns based on header value


Recommended Posts

Hello everyone,

I'm new to AutoIt scripting. I was wondering if someone could help me with my script? 

My table in Excel is this:

DBN            Description         Amount

123              Some Text          13.00

I want to hide the columns that don't contain specified header text.

   $oRange = $oWorkbook1.ActiveSheet.Usedrange.SpecialCells($xlCellTypeVisible)

   If $oRange <> "DBN" Then
         $oRange.EntireColumn.Hidden = True
      Else
         $oRange.EntireColumn.Hidden = False
   EndIf

 

Link to post
Share on other sites

Use _Excel_RangeFind to find the address of the cell/column and then just use something like the following to hide the column.

#include <Array.au3>
#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, "C:\Program Files (x86)\AutoIt3\Examples\Helpfile\Extras\_Excel1.xls")
If @error Then
    _Excel_Close($oExcel)
    Exit
EndIf

Local $aResult = _Excel_RangeFind($oWorkbook, "This is a long Story", "A1:M1", Default, $xlWhole)
For $i = UBound($aResult) - 1 To 0 Step - 1
    $aSplit = StringSplit($aResult[$i][2], "$", 2)
    $oSelect = $oExcel.Columns($aSplit[1] & ":" & $aSplit[1]).Select
    $oExcel.Selection.EntireColumn.Hidden = True
Next

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...