Formula bar values excel vba - excel

I have value in cells 10.0 but in the formula bar is 10 so if I copy
The value to another cell like
Range(”a1”)= Range(”b1”) I got 10 instead 10.0
Or I copy to another workbook
For display value work good but for formula bar no
I used number format did not work so if you can help me
Excel vba
Thank’s

#Jeeped, Gosh you're not wrong. Not sure what I was thinking there.
Range("a1") = Range("b1")
Range("a1").NumberFormat = "#0.0"

Related

Find discrepancy between specific columns in 2 worksheets

I am working with excel, let's say worksheet ABC with columns C3:O102 contains "-" while worksheet DEF with columns C3:O102 contains "yes". I want the cells with discrepancy to return "Discrepancy". I tried excel formulas, I couldn't figure it out so I tried with VBA and it didn't run.
Sub IF_Then()
If Worksheets("Sheet15").Range("C3:O102").Value = "-" And Worksheets("Sheet30").Range("C3:O102").Value = "yes" Then
Worksheets("Sheet30").Range("AJ3:AJ103").Value = "Discrepancy"
End If
End Sub
This can easily be done, using the IF() worksheet function, as in my example: I have created two sheets (Blad1 and Blad2), I have filled in cells "A1:A5", and in a third sheet, I've added the following formula in cells "A1:A5" (starting in cell "A1" and dragging down):
=IF(Blad1!A1 = Blad2!A1;Blad1!A1;"Discrepancy")
(Keep out, my regional settings require semicolons inside a formula, some require commas.)
I ended up using it without VBA. I got accurate results with this excel formula. The formula was really long because I was working with a lot of sheets and kind of like dissimilar data.
=IF(AND(INDEX(MATCH),(MATCH)))
I appreciate the contribution

Excel, Create a named range from the contents of cells usign cell formulas

I am stuck...
I have a 100 Row sheet with 10 Columns. This list is broken into classes simply by inline headers. I have definitions of the blocks of data under each head, for example:
UNASSOCIATED A2 A19
HOSTS A21 A32
ROOF A34 A100
I compute those ranges as they may change from time to time. I need
first: Define Name of each group by formula
Second: From time to time select the defined group
I am unable to get a formula to work which will allow me to use the "Content" of the cell as opposed to the cell location to define these ranges.
I'm stuck.
Suggestions would be appreciated.
Regards,
RHD
This cannot be done in a cell formula. You'll need to create a macro (VBA) to do this. Essentially, what you need is to grab the value of a cell then use that value as if it were a cell address.
Take a look at the example macro below. If cell A1 contains the characters "B22", then x will become the value of A1 (which is "B22") and "test" will be written to cell B22. This cannot be done in with cell formulas.
Sub test()
Dim x As String
x = Range("A1").Value
Range(x).Value = "test"
End Sub
A good amount of adaptation will been needed to incorporate this technique, and you'll need to play with this a bit. Ping this community to help answer more specific questions as they come up.

Exporting formulas to excel from ssrs 2008R2

I am aware that in 2008 the method of exporting formula to excel was downgraded see here.
But I have seen a workaround for a static formula where the same formula is required (see Here and here). However I have the case where I need a relative formula when I export to excel. Is there a newer solution out there does anyone know?
This is my workings so far
The result I am after is cell (T,r3) = cell (R,r3)-cell(O,r3) and then cell (T,r4) = cell (R,r4)-cell(O,r4) and so on in excel I would expect to see
in cell T3 the formula =R3-O3
and cell T4 the formula =R4-O4
O!P!Q!R !S!T!
r3 1 5 N 5 4
r4 3 5 N 10 7
(Sorry I can not get the table to line up)
my ssrs expression is
="=R"+cstr(RowNumber("DataSet1")+2)+"-O"+cstr(RowNumber("DataSet1")+2)
where DataSet1 is what my ssrs tablix is based on and the +2 element is to offset to allow how the titles of the report and the table move the first row of data down the excel sheet.
The output is achieve in the cells when exported to excel is the formula as text in the cell content and if I click into the cell and press backspace and return the formula works. It appears that some white space is being exported or excel just treats every thing as text on the import routine
I can of course use and find and replace on this statement in excel
="=R"+cstr(RowNumber("DataSet1")+2)+"-O"+cstr(RowNumber("DataSet1")+2) as suggested but was trying to be more elegant
I do not suppose you can export some code to run in excel as vba to do the find and replace function at a button press for the user?
Has anyone any suggestions - thanks
Ian
Since this is not supported the workaround is tedious. For each cell that has a formula you can:
Select the cell
Click in the formula bar
Press Enter
This causes Excel to evaluate the string as a formula and replaces the text with the value it represents.
You can't export VBA from SSRS but you could paste in your own VBA after export and run it to accomplish the same steps.
I use SSIS to populate an Excel report template with data and formulas.
I had too many formulas to have to go into the worksheets and updated them manually.
In a script task, I use VB to calculate the formula and populate it in a sheet as well as underline the appropriate line:
ExcelFormula = "=SUM(" & SumColumn & "45:" & SumColumn & Row.ToString & ")"
Worksheet.Cells(Row, Column - 1).Formula = ExcelFormula
Worksheet.Cells(Row, Column - 1).BORDERS(9).Weight = 2
Worksheet.Cells(Row, Column).BORDERS(9).Weight = 2
It's a bit more work initially but once you get it set up to work with one cell, the rest are relatively easy.

How to convert the result (as displayed) in the cell to text in Excel

I have formatted a cell in Excel as Scientific with 1 decimal place then I inserted a number in it like (0.41). After pressing enter the result displayed is (4.1E-01). My aim is to put this result in a cell with text format so that when I double click the cell, I can copy/modify the text (4.1E-01) as I want.
I tried to format that cell as text but the result gets back to 0.41. I also tried to copy the cell and paste the value only using "Special Paste" into a text-formatted cell but the result keeps returning to 0.41. Do you have a suggestion on how to solve this issue?
Thanks in advance
This is a bit of a work around unless you want to use VBA. In an adjacent cell type this formula:
=TEXT(A1,"0.00E+00")
Now you can copy that cell and paste values only and get just the text:
2.22E+27
If your okay with VBA use this:
Range("A2").Value = Range("A1").Text

Write IF statement using FormulaR1C1 in VBA Excel

I have the following formula
=IF((GLOBAL_DATE-30)<G2,"1 Month",IF((GLOBAL_DATE-60)<G2,"2 Month",IF((GLOBAL_DATE-90)<G2,"3 Month","Older Than 3 Months")))
and I would like to write this into specific cells using the FormualR1C1 in VBA.
(the GLOBAL_DATE is a named cell on another sheet)
Thanks
Select the cell that has that formula. In the VBE, go to the Immediate Window and type
?Activecell.FormulaR1C1
and press enter. That will give you the R1C1 translation of your formula.
This is what I get using the Macro Recorder:
ActiveCell.FormulaR1C1 = _
"=IF((GLOBAL_DATE-30)<R[1]C[6],""1 Month"",IF((GLOBAL_DATE-60)<R[1]C[6],""2 Month"",IF((GLOBAL_DATE-90)<R[1]C[6],""3 Month"",""Older Than 3 Months"")))"
That is using relative cell addresses (R[1]C[6] is the cell one row below and 6 columns to the rigth from the ActiveCell. Alternatively, you can use absolute adresses by replacing R[1]C[6] by R2C7 (for row 2, column 7 = G2).
You can easily use VBA to translate those formulae that you entered in a sheet into a sytax that's suitable for VBA. I once wrote a sub for that purpose.

Resources