Sign in to follow this  
Followers 0
Nurav

Alternate "Range" notation in Excel.

7 posts in this topic

I have this piece of code for generating an excel graph.

Can some one help me in defining the "Range" in a different numerical way?

ex. can i set the range as 1,1:2,2 instead of A1:B2? (This is not working anyway!)

thanks in advance.

Dim $oXL ;2
    $oXL = ObjGet($FilePath)

    $oXL.Windows(1).Visible = 1
    $oXL.Worksheets(1).Activate
    $oXL.ActiveSheet.Visible = 1
    $oXL.Application.Visible = 1
    $oXL.Charts.add()
    $oXL.ActiveChart.ChartType =51 ;bar chart= 51
    $oXL.ActiveChart.SetSourceData($oXL.Worksheets(1).Range(A1:B2))

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can select your range like this:

$oXL.Range("A1" ).Select
$oXL.Range($oXL.ActiveCell.Offset(0, 0), $oXL.ActiveCell.Offset(6, 1) ).Select
Edited by JoHanatCent

Share this post


Link to post
Share on other sites

I use the following code written by Spiff58 to convert numbers into columns.

; ===============================================================================================================================
; Convert column numbers to excel column letters
; Written by Spiff59
; http://www.autoitscript.com/forum/index.php?showtopic=115665
; ===============================================================================================================================
Func _ExcelColumnLetter($iColumn = 0)
    Local $letters
    While $iColumn
        $x = Mod($iColumn, 26)
        If $x = 0 Then $x = 26
        $letters = Chr($x + 64) & $letters
        $iColumn = ($iColumn - $x) / 26
    WEnd
    Return $letters
EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You can select your range like this:

$oXL.Range("A1" ).Select
$oXL.Range($oXL.ActiveCell.Offset(0, 0), $oXL.ActiveCell.Offset(6, 1) ).Select

Selecting a range with reference to the current active cell seems to be a workaround. I am wondering if there is an absolute way to do this.

Please refer this topic:

http://www.xtremevbtalk.com/showthread.php?t=112863

there it says,

The Range() property (essentially is a function) cannot accept R1C1-style notation for the input string. It can take either strings of A1 notation, or Cell/Range inputs.

The following all *attempt* to Select the same Range:

Range("A1:E10").Select ' Works fine.

Range("R1C1:R5C10").Select ' FAILS!

Range(Cells(1, 1), Cells(5, 10)).Select ' Works fine.

What can be the AutoIt equivalent of last statement? (Range(Cells(1, 1), Cells(5, 10)).Select)

Share this post


Link to post
Share on other sites

According to the Excel UDF function _ExcelNumberFormat the last example (Range(Cells(1, 1), Cells(5, 10)).Select ) should read:

With $oExcel.ActiveSheet
  .Range(.Cells($sRangeOrRowStart, $iColStart), .Cells($iRowEnd, $iColEnd) ).Select
EndWith

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

What can be the AutoIt equivalent of last statement? (Range(Cells(1, 1), Cells(5, 10)).Select)

Try:

$oXL.Range($oXL.Cells(1, 1), $oXL.Cells(6, 2)).Select
Edited by JoHanatCent

Share this post


Link to post
Share on other sites

Try:

$oXL.Range($oXL.Cells(1, 1), $oXL.Cells(6, 2)).Select

$oXL.ActiveChart.SetSourceData($oXL.Range($oXL.Worksheets(1).Cells(1, 1), $oXL.Worksheets(1).Cells(11, 5)))

This worked like a charm! thank you all...:x

@water: now we don't need a function to convert number to alphabet! Yeeeeeee!!!!

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