Jump to content

Recommended Posts

Posted

Hey All,

 

I have an excel worksheet, about A1:BD1500, and trying to replace all blank cells to zero, but following code doesn't work. What did i do wrong?

Local $oRange = $oWorkbook.ActiveSheet.UsedRange.SpecialCells($xlCellTypeBlanks)
_Excel_RangeReplace($oWorkbook, $oWorkbook.ActiveSheet, $oRange, "", "0")
ConsoleWrite($oRange & @CRLF)

the console writes nothing about $oRange, which I believe the first line code doesn't find the cells. Any ideas? Thank you for your help!

Posted

A range is an object that can not be displayed using ConsoleWrite.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

What is the value of @error and @extended after you called _Excel_RangeReplace?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 5/7/2018 at 9:21 PM, water said:

What is the value of @error and @extended after you called _Excel_RangeReplace?

Expand  

it actually has no error, its says successfully replace. but actually nothing is replaced for those blank cells.

and this is my error code

If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace", "Error replacing data the range." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace", "Data successfully replaced in cells.")

 

Posted

I assume that the UsedRange property returns an area, not a range. An area is a collection of ranges.
Could you try:

Local $oArea = $oWorkbook.ActiveSheet.UsedRange.SpecialCells($xlCellTypeBlanks)
For $oRange in $oArea
    _Excel_RangeReplace($oWorkbook, $oWorkbook.ActiveSheet, $oRange, "", "0")
Next

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 5/8/2018 at 7:14 PM, water said:

I assume that the UsedRange property returns an area, not a range. An area is a collection of ranges.
Could you try:

Local $oArea = $oWorkbook.ActiveSheet.UsedRange.SpecialCells($xlCellTypeBlanks)
For $oRange in $oArea
    _Excel_RangeReplace($oWorkbook, $oWorkbook.ActiveSheet, $oRange, "", "0")
Next

 

Expand  

Hey Water, thank you so much. I tried this code, and add the error script just before Next

If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace", "Error replacing data the range." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeReplace", "Data successfully replaced in cells.")

the error msg is 3: $sSearch is empty. I am not sure what should I do about this. Thank you so much for helping me

Posted

You can use:

$oExcel.Application.ActiveWorkbook.Sheets(1).Range("E5:J20").Select
$oExcel.Application.Selection.Replace("", 0)

Posted
  On 5/8/2018 at 9:04 PM, junkew said:
In excel VBA it would be like this
Range("A1:BD1500").SpecialCells(xlCellTypeBlanks).value=0

This would then become in AutoIt with excel udf

$oWorkbook.ActiveSheet.Range("A1:BD1500").SpecialCells($xlCellTypeBlanks).value=0

 

Expand  

This code works! thank you so much Junkew!

Posted
  On 5/9/2018 at 7:19 AM, Juvigy said:

You can use:

$oExcel.Application.ActiveWorkbook.Sheets(1).Range("E5:J20").Select
$oExcel.Application.Selection.Replace("", 0)

Expand  

Your codes works too! Thank you so much Juvigy!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...