ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   formatting cells script/marco (https://www.excelbanter.com/excel-programming/277236-formatting-cells-script-marco.html)

Jan Agermose

formatting cells script/marco
 
I'm writing data into an excel document using c# but the result is not
really what I want. All my integer/double data is written as strings. When I
open the document an optionicon is displayed on the columns holding
"misformatted data" allowing me to convert all integer-but-string-formatted
data into proper integer data (same for double). Now as I don't want do this
on every column that needs "fixing" I would like to have a script or macro
in excel that would perform this task for me - on loading or saving the
document.

Is this possible, and as I actually does not know any VB or excel macro,
does anyone have an example that I could easily use or extend?

Jan Agermose



Dave Peterson[_3_]

formatting cells script/marco
 
Something like this:

Dim myCell As Range
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = Intersect(.UsedRange, .Range("a:c,e:f,h:h"))
Set myCell = .Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 1)
myCell.Copy
myRng.PasteSpecial operation:=xlPasteSpecialOperationAdd
End With

It's the equivalent of copying an empty cell
and paste|special|and checking add
to all those cells that have numbers formatted as text.

Maybe in your auto_open/workbook_open code?


Jan Agermose wrote:

I'm writing data into an excel document using c# but the result is not
really what I want. All my integer/double data is written as strings. When I
open the document an optionicon is displayed on the columns holding
"misformatted data" allowing me to convert all integer-but-string-formatted
data into proper integer data (same for double). Now as I don't want do this
on every column that needs "fixing" I would like to have a script or macro
in excel that would perform this task for me - on loading or saving the
document.

Is this possible, and as I actually does not know any VB or excel macro,
does anyone have an example that I could easily use or extend?

Jan Agermose


--

Dave Peterson



All times are GMT +1. The time now is 08:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com