Jump to content

Excel - Go to Next Column


Go to solution Solved by TheSaint,

Recommended Posts

Posted

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
  • Solution
Posted

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.

  Reveal hidden contents

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

Posted

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:

  Reveal hidden contents

 

Posted
  On 11/17/2014 at 5:24 AM, water said:

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.

Posted

Choose the solution that best fits your needs :)

My UDFs and Tutorials:

  Reveal hidden contents

 

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
×
×
  • Create New...