Jump to content
xcaliber13

Excel column shift help

Recommended Posts

xcaliber13

Just a quick question about excel and shifting columns.   I use this code  works great:

For $a = 1 To $aLastRow
    $aCell = _Excel_RangeRead($oWorkbook, Default, "Q" & $a)
    If $aCell = "S"  Then _Excel_RangeInsert($oWorkBook.Activesheet, "Q" & $a, $xlShiftToRight)
Next

But this only shift to the right one(1) column.   Now my question:

Is there a way to code this to shift to the right X amount of columns?   So instead of just shifting over one(1) column is there a way to make it shift over lets say 3 columns?

thank you

Share this post


Link to post
Share on other sites
water

Check example 2 in the help file for how to insert > 1 column.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
xcaliber13

water,

        Thank you for the reply.   I tried what the example 2 showed to do but nothing gets moved.  Here is what I tried.

For $a = 1 To $aLastRow
    $aCell = _Excel_RangeRead($oWorkbook, Default, "Q" & $a)
    If $aCell = "S"  Then _Excel_RangeInsert($oWorkBook.Activesheet, "Q:T" & $a, $xlShiftToRight)
Next

I am I not understanding the example correctly?

Share this post


Link to post
Share on other sites
water

I think it should be:

"Q" & $a & ":T" & $a

So on row 3 you would insert Q3:T3


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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
xcaliber13

Water,

          Once again you are correct.   That is what works.

Thank you

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - 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

×