Jump to content

Excel Inserting #N/A on blank cells


goku200
 Share

Recommended Posts

Not sure what's going on with my script, but when I range read the contents in column A and then write them to column E it inserts the contents but it also inserts #N/A after all the way down to row  1048576. What am I missing from my script? Below is my script

 

Edited by goku200
Link to comment
Share on other sites

A few thoughts:

  • _Excel_SheetAdd: You can't have multiple sheets with the same name ("Test") in a workbook
  • _Excel_RangeDelete: If you want to delete row 1 then delete row 1, not all cells in this row. Means: _Excel_RangeDelete($oWorkbook.ActiveSheet, "1:1")
    Your parameter 3 with the value of 2 is definitely wrong.
  • _Excel_RangeInsert: Your parameter 3 with the value of 2 is definitely wrong.
  • _Excel_RangeDelete: When deleting a column using parameter $xlShiftUp doesn't make sense.
  • Check the dimensions (number of rows and columns) of $Array2. How many rows/columns do you get?
  • You should check @error / @extended after each _Excel_* function call

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

4 hours ago, water said:

A few thoughts:

  • _Excel_SheetAdd: You can't have multiple sheets with the same name ("Test") in a workbook
  • _Excel_RangeDelete: If you want to delete row 1 then delete row 1, not all cells in this row. Means: _Excel_RangeDelete($oWorkbook.ActiveSheet, "1:1")
    Your parameter 3 with the value of 2 is definitely wrong.
  • _Excel_RangeInsert: Your parameter 3 with the value of 2 is definitely wrong.
  • _Excel_RangeDelete: When deleting a column using parameter $xlShiftUp doesn't make sense.
  • Check the dimensions (number of rows and columns) of $Array2. How many rows/columns do you get?
  • You should check @error / @extended after each _Excel_* function call

@water Thank you for the reply. I went ahead and updated the script with 1:1. The script only creates one Worksheet Test. The first tab is by default Sheet1 when script runs it creates second tab sheet (Test). I also changed the _ExcelRangeDelete to $xlshiftDown for Column A since that is what's being deleted...The dimensions of $Array2 displays the correct Column A with the contents in it. The reason why I have the _ExcelRangeInsert with column E:E is because my data varies. It could be 100 rows, 200 rows, or 1000 rows....

Edited by goku200
Link to comment
Share on other sites

I am having a bit of hard time to follow your script.  But here are my thoughts (since this code is unrunable for me) :

1- remove those lines from the loop as they are repeating redundantly the same things

_Excel_SheetAdd($oWorkbook, -1, False, 1, "Test")
 Local $FileList = _FileListToArray("C:\Test\", "*.*")
_ArrayDisplay($aArray2)

2- You are writing a single value to the whole column (that is the problem IMO)

_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray2[$i], "E:E")

 

Edited by Nine
Link to comment
Share on other sites

On 2/14/2022 at 9:21 AM, Nine said:

I am having a bit of hard time to follow your script.  But here are my thoughts (since this code is unrunable for me) :

1- remove those lines from the loop as they are repeating redundantly the same things

_Excel_SheetAdd($oWorkbook, -1, False, 1, "Test")
 Local $FileList = _FileListToArray("C:\Test\", "*.*")
_ArrayDisplay($aArray2)

2- You are writing a single value to the whole column (that is the problem IMO)

_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray2[$i], "E:E")

 

Removing that did the trick @Nine Thanks all for your assistance 🙂

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...