Ahile07

Excel - write in file

2 posts in this topic

Hello guys,

 

Hopefully somebody can help me in this matter.

I try to write a program that can help me log 2 variables in excel.

I want to use 2 fields to declare tha value for these variables. For example: name and surname.

I want after i write them in background to log them into an excel file: 1 column for name and 1 for surname.

But i don't know how to make it work so that everytime i'm putting a new set of values to put them in a new line so that my excel sheet will start to collect multiple values for my variables.

Hopefully i'm clear enough with what i want to make.

I've searhched big time on google and on forum for simple examples....i can't find any that simple...all of them seems to be so complicated :D and i can't use them to make what i want too.

Obviously i can make it write in specific cells. But i want the Cell number to increase automatically when i have different sets of values.

See example:

$read = _Excel_RangeRead($workbook, $workbook.Activesheet, "A1", 1)
_Excel_RangeWrite($workbook, $workbook.Activesheet, "Test", "A1")

Thank you in advance for any ideas.

Share this post


Link to post
Share on other sites



You need to calculate the place where you want to write to. In your case it is the first unused cell. So we first need to calculate the last used cell, get the row number of this cell, add 1 to it and voilá.

$oRange = $oWorkbook.ActiveSheet.UsedRange.SpecialCells($xlCellTypeLastCell) ; Gets the last used cell
$iRow = $oRange.Row ; Row number of the last used cell 
$iRow = $iRow + 1 ; increment by 1 to get the first unused row
$sRange = "A" & $iRow ; Cell where you want to write to

Details can be found in the wiki.
 


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

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