Jump to content

Excel - Go to Next Column


litlmike
 Share

Go to solution Solved by TheSaint,

Recommended Posts

Let's say that I want to loop the numbers 1 through 5, and on each iteration it should write to the next column in Excel.  So, I just want to put the number 1 in A1, 2 in B1, 3 in C1, 4 in D1, and 5 in D1.  How do I increase the column letter programamatically with the new Excel UDF?

Thanks!

For $iStartingColumn = 1 To 5
_Excel_RangeWrite($oWorkbook, Default, $iCC, $iStartingColumn & "1")
Next
Link to comment
Share on other sites

  • Solution

The quick simple way.

For $i = 1 To 5
     iStartingColumn = Chr(64 + $i)
     _Excel_RangeWrite($oWorkbook, Default, $iCC, $iStartingColumn & "1")
Next

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Put the numbers into a 2D array (1 row, 5 columns) and write the Array to A1 by calling _Excel_RangeWrite.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Put the numbers into a 2D array (1 row, 5 columns) and write the Array to A1 by calling _Excel_RangeWrite.

That is an elegant solution, and I don't know why I didn't think of that earlier.  In this particular case, it actually works better to use the CHR() because I am working with permutations, sets, etc.  But, I think the array works better in most other situations.

Link to comment
Share on other sites

Choose the solution that best fits your needs :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

×
×
  • Create New...