How can format multi condition in EPPlus? - epplus

Value of Cell = 25.132697889076045
In Excel I set Custom format:
"[>=99.95]0;[>=0.995]0.0;0.00"
Excel can display Text = 25.1
But with Epplus , i getting Text =25
oSheet.Cells[iRow, iCol].Text
Why Epplus not format with condition format "[>=99.95]0;[>=0.995]0.0;0.00"?

Related

Vba turns cell in to date on mistake

Hi how can I get around vba is converting a cell automatic to a data format when I add a value like 10 - 12 I just want the value in the cell to be 10 - 12 not a date
the code I use is "cFli is the value 10 - 12":
tsheet.Range("E2").Value = cFli
You can prepend a single-quotation mark to the value of a cell, which indicates to Excel to treat the rest of the string as text:
tsheet.Range("E2").Value = "'" & cFli
Note: The ' does not become part of the cell contents, although it will appear when editing the cell in future.
Alternatively, you can achieve the same thing by formatting the cell using the Text format:
tsheet.Range("E2").NumberFormat = "#"
tsheet.Range("E2").Value = cFli
Note: The formatting must be done before putting the value into the cell.

Restricting the text to be entered in a cell with Custom Formula (Data Validation)

I've a string in a Cell which contains a date in YYMMDD format in it's first 6 characters. I want to restrict the user to enter only the value which is greater than or equal to current date.
170712 should be allowed as it's greater than or equal to current date 170712.
With VBA, the following formula is working fine:
CLng(Left(Range("H10").Value, 6)) >= CLng(Right(Year(Date), 2) & Format(Now, "MMDD"))
The same formula is not working when put it custom formula under data validation !
How should I put this in Data Validation Custom Formula Field in excel so I can restrict user the way I mentioned above?
you will have to put today() in a cell, and do the data validation for Date with refrence to >= to that cell. Inside data validation.
Try this custom formula in data validation.
=(DATEVALUE(TEXT(B1,"mm/dd/yy"))>=DATEVALUE(TEXT($A$1,"mm/dd/yy")))
The above formula is to apply data validation in Column B when the date 170712 is in cell A1
The code would be like this.
If Range("h10") >= Format(Date, "yymmdd") Then
If the cell of validation is b1 cell, the validation formula is bellow.
=B1>=TEXT(TODAY(),"yymmdd")

Excel VBA: Cycling through cells and inputting values

I am trying to write a vba macro that essentially does this:
Input value for E97
Input value for E98
...
Input value for E102
Then
Input value for F97
Input value for F98
...
Input value for F102
and this cycles until col I
After I need to do the same thing for cells E-I 105:110, 113:118, 121:126
Pertinent to your rather brief definition: to assign the same value (e.g. 1234) to the range of Excel cells use the following VBA code snippet:
Dim example As Range
Set example = Range("E97:E108")
example.Value = "1234"
The same applied to any other range (e.g. F97:F108). Rgds,

Excel VBA to force numeric value into time format

There are two columns copied into a workbook from a Access database.
I want to ensure that the data is formatted correctly so I added this code:
'DateTime Column
Sheets("Sheet1").Columns("A:A").Select
Selection.NumberFormat = "m/d/yyyy hh:mm"
'Time Column
Sheets("Sheet1").Columns("B:B").Select
Selection.NumberFormat = "hh:mm"
The datetime column formats correctly.
The time column is initially copied as a numeric equivalent (ie 0.595277777777778) instead of the time value (14:17).
Running the macro code does nothing to the visual display and it isn't until I hit F2 and enter on the cell that the format applies.
Is there a method (short of a loop) to force Excel to apply the formatting?
You can use VBA to accomplish the same effect as Steve Homer's answer by setting the range's value property to itself:
Dim r As Range
Set r = Sheets("Sheet1").Columns("B:B")
r.Value = r.Value
If you copy the column and paste as values (through a macro if needs be) then Excel should re-interpret the data type and the above should work correctly.
You can do this with out declare TMP as DATE:
TMP = CDate(Range("A1").Value) ' we suppose A1 value is 12:45:00
TMP = "" & TMP ' convert to char
TMP = Left(TMP, 5) ' extract the first 5 char
MsgBox TMP ' for displaying 12:45

VB.NET Code to Change Excel 2007 Column Cell Format to Number no Decimal

VB.NET code to change Excel 2007 Column Cell Format from Text to a Number no Decimal.
Right now Column F shows values that look like
3E+13
3E+13
Manually changing it to a Number with No Decimal shows the correct value.
30000046605562
30000041582875
Of course I would like to automate this.
Select the rows (maybe programmatically) and perform
Selection.NumberFormat = "0"
To select all cells in the sheet call
Cells.Select