IF DATE in cell, return Date; IF cell is blank or has text, return N/A or Blank - excel-2010

EXCEL 2010 - I need a formula in cell W5 that will return what's in cell H5 which is either:
a short date (7/4/2019) or blank or text.
i.e. If cell H5 has a date, return date; if cell H5 is blank OR has text (anything other than a date), return N/A or even leave it blank.
I know this is probably easy but can't seem to get it correct. If needed, the date range will be 7/4/2019 thru 7/26/2019).
As a side note, I will be using this formula in 2 areas and need dates to be in correct format because they will then be used to subtract to get days between.

This can easily be done with a custom UDF.
Public Function bIsDate(rng As Range) As Boolean
If isDate(rng) Then bIsDate = True
End Function
To create a custom UDF, follow these steps:
In Excel, press ALT + F11 to open the VBE.
Go to Insert > Module
Paste the above code into the new window and exit the VBE
Press F12 in Excel to open up the SaveAs dialog box
Save it as a Macro-Enabled Workbook
Now you have a brand-new worksheet function bIsDate(). You can go into any cell and type in =bIsDate() and you will now see it autocomplete.
Place this in your W5 Cell:
=If(bIsDate($H5), $H5, "")

Related

Display text representation of a date as a formula result

I get this date format from Zapier
2018-08-16T01:13:58
I use this formula to split and extract the first half of the split (the date).
=index(SPLIT("2018-08-16T01:13:58","T"),0,1)
Google Sheets displays the formula output as a number, e.g. 43328
If I format this cell manually, using the menu Format >> Number >> Date, Google Sheets will display it as the formatted date, e.g. 16/08/2018
If I use DATEVALUE() as such:
=datevalue(index(SPLIT("2018-08-16T01:13:58","T"),0,1))
then the cell displays #VALUE!
Error DATEVALUE parameter '43328' cannot be parsed to date/time.
How can I write my formula such that it is displayed as formatted date, without having to format the formula's cell through the menu?
You can use the TEXT function:
=TEXT(43328,"dd-mm-yyyy")
Date shows in google spreadsheet are formatted by google spreadsheet settings. If you want to change the datetime format of your sheet, you will have to change Locale setting to that of your need.
If you don't want to go over settings, you can set it manually by code.
First, you will need to put this formula =SPLIT("2018-08-16T01:13:58","T") + "" somewhere to get the date value. Here I assume you use cell "Z1"
Now, you will have to change the date format each time "Z1" changes it value. I use onEdit(e)
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSheet()
if (range.getColumn() == 26 && range.getRow() == 1) { // if Z1 is modified
var d = ss.getRange("Z1").getValue()
var inputDate = Utilities.formatDate(d, "GMT+7", "dd/MM/yyyy")
ss.getRange("B5").setValue(inputDate)
}
}
There you go. Each time Z1 change, which means the date value is inputted, the correct date + format will be reflected in B5.
After much searching this seems to work for me.
=regexreplace(SUBSTITUTE(SPLIT("2018-08-16T10:02:29","T") + "","-","/"), "^(\d+).(\d+).(\d+)$", "$3/$2/$1") & " " & regexreplace(RIGHT("2018-08-16T10:02:29", find("T","2018-08-16T10:02:29") -3), "^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$", "$1:$2:$3")
Outputs 16/08/2018 10:02:29

How to format currency columns in Axlsx?

I am using ruby Axlsx gem for writing my clients accounts data in xlsx. Now I am appending " Dr" string to all debit amounts which is making amount as a string e.g. "1000 Dr". I want to append " Dr" but the amount should still be an integer and excel should give sum at bottom when column is selected.
What I am doing, notice that excel shows sum = 0 in bottom-right even on selecting :-
What I am doing, notice that cell remains a string on selecting (880 Dr should become 880.00 on selecting the cell):-
What I want to do, excel should show sum of selected colums as shown by excel in bottom-right sum=1957.00 Dr:-
What I want to do, the cell should be converted to number when double clicked (1341.00 Dr has become 1341 on selecting)but Dr should be visible on unselecting again:-
I solved this by using custom format_code
custom_format = sheet.styles.add_style(:format_code => "#.00 "Dr"")

Google Sheets Export to Excel values instead of formulas

I have a google sheet where the cells in the first tab pull data from cells on the second tab.
for example Sheet1 cell A1 has =Sheet2!A1
This is true for every cell on Sheet1
When I do a File - Download As - Microsoft Excel (.xlsx)
It exports the cells with formulas. Is there a way to export the sheets as values and not formulas
In this case, Sheet1 cell A1 would not contain =Sheet2!A1 but the value of =Sheet2!A1?
You can copy your original google spreadsheet and, in the copy, change the formula for the first cell for each tab to import data from the original one:
=IMPORTRANGE("spreadsheet id","'tab name'!range")
Ex:
=IMPORTRANGE("1C-PS4wAHS8ssCNgVDfOsssREAz7PjuQGX23Rk0sssss","'measurement with spaces'!A12:F44")
The ID you can get via original spreadsheet URL:
https://docs.google.com/spreadsheets/d/1C-PS4wAHS8ssCNgVDfOsssREAz7PjuQGX23Rk0sssss/edit#gid=99999999
The exported xlsx file from the copy will have only the values
#fabceolins answer is simple and good for normal scenarios, i noticed however Excel will still contain reference to IMPORTRANGE formula which can cause access issues.
I created Google App script to copy in the following method.
If you can use Google App scripts, add the following functions:
function update_view(dup_id, TL="A1", BR="Z991") {
// Open current Sheet
var ss = SpreadsheetApp.getActiveSpreadsheet()
// Supply a duplicate google doc ID. This document will be exported to excel
var ds = SpreadsheetApp.openById(dup_id)
// UI element for notifying in the google sheets
var ui = SpreadsheetApp.getUi()
//Copy each sheet one by one
var sheets = ss.getSheets();
for (i=0; i<sheets.length; i++) {
src_sheet = sheets[i];
sheet_name = src_sheet.getName();
// If same sheet exists in the destination delete it and create an empty one
dst_sheet = ds.getSheetByName(sheet_name);
if (dst_sheet != null) {
ds.deleteSheet(dst_sheet)
}
dst_sheet = ds.insertSheet(sheet_name);
//set column width correctly
for(j=1; j<=src_sheet.getLastColumn(); j++){
dst_sheet.setColumnWidth(j, src_sheet.getColumnWidth(j))
}
src_range = src_sheet.getRange(TL + ":" + BR);
dst_range = dst_sheet.getRange(TL + ":" + BR);
//Note: DisplayValues is set as Values, formulas are removed in dup sheet
dst_range.setValues(src_range.getDisplayValues());
//Nice to haves for formatting
dst_range.setFontColors(src_range.getFontColors());
dst_range.setFontStyles(src_range.getFontStyles());
dst_range.setBackgrounds(src_range.getBackgrounds());
dst_range.setHorizontalAlignments(src_range.getHorizontalAlignments());
dst_range.setVerticalAlignments(src_range.getVerticalAlignments());
dst_range.setWraps(src_range.getWraps());
dst_contents_range = dst_sheet.getDataRange();
dst_contents_range.setBorder(true, true, true, true, true, true);
}
//Completed copy, Now open the dup document and export.
ui.alert("Backup Complete, Please open " + dup_id + " sheet to view contents.")
}
function update_mydoc_view(){
// https://docs.google.com/spreadsheets/d/<spreadsheet_id>/
update_view("<spreadsheet_id>")
}
To run the function, go to tools->macros->import , import the function and run update_mydoc_view().
After it is completed, export the google sheet into an excel document.
If you want to download a single sheet spreadsheet, instead of download it as .XLSX, download it as .CSV.
If by open the .CSV file by double clicking it shows strange characters, the default encoding of your computer is different from the one used by the Google servers, to fix this do the following:
Open Excel
Click File > Open
Select the .CSV file
The import wizard will be shown. One of the steps will allow you to select the file encoding, select UTF-8.
Once you finish with the import wizard save your file as .XLSX
Related
Microsoft Excel mangles Diacritics in .csv files?
Is it possible to force Excel recognize UTF-8 CSV files automatically?
I did the following and it worked for me :
Duplicate the file
CTRL+A > CTRL+X > CTRL + V Paste Value only (from the paste icon displayed after pressing CTRL+V)
If you want to keep only the values from Sheet1, just select the data in the sheet, copy it, open a new Excel work book and when you paste, rather than using the conventional hotkeys Ctrl+V, right click cell A1 and select Paste values under the Paste options category of the right click menu.
If the problem is that the downloaded Excel does not have functional formulas that take information from your second sheet and instead show the formulas as text, do what the previous commenter said. check your view to make sure you are not in formula view. use the hotkey Ctrl+ ~, or go to the view tab to check your view options.
By default this is what happens - you will see the values not the formula.
Are you sure you are not in formula view in Excel?
If you check "Show formula" it will switch in formula view.
Or generally speaking you can try those:
MS Excel showing the formula in a cell instead of the resulting value
I would be surprised if it was indeed a google sheet problem - it's about Excel display.

Apply 3-color scale to an entire row in Excel 2010.

I have an table in an MS Excel 2010. The table has two columns. The first column is a name of a person (Col A), the second column is the marks that the person secured in an exam (Col B).
I am applying conditional formatting. If I choose the following wizard
Home > Conditional Formatting > Format all cells based on their values
I can color the Col B on a 3-color scale. This is exactly what I want. However, I want it for the entire row and not only the cell in Col B. I want the name also to be formatted in the same color as the marks.
Anyone knows how to do this?
I have already looked around a bit. The following came close to did not solve the particular problem that I am trying to.
http://www.howtogeek.com/howto/45670/how-to-highlight-a-row-in-excel-using-conditional-formatting/
Conditional Formatting Rows Based on Date
You're probably going to have to use VBA code for this.
Right click the worksheet label and select 'View Code'
Inside the code window, paste in the following code:
Sub RunMe()
Dim xRng As Range, xCell As Range
With Me
Set xRng = .Range(.Cells(2, 2), .Cells(.Rows.Count, 2).End(xlUp))
' Change the first '2' above to reflect the starting row of your data
For Each xCell In xRng
xCell.Offset(0, -1).Interior.Color = xCell.DisplayFormat.Interior.Color
Next xCell
End With
End Sub
Now every time you run the macro (Alt-F8, select macro), column A will be formatted with the conditional formatting assigned to column B.
If you want this process to be automatic, change:
Sub RunMe()
to something like:
Private Sub Worksheet_Activate()
' This will run the macro whenever the worksheet is selected
or you could assign the code to a keyboard shortcut or a command button etc.
If you would like the code to run every time the file is opened, saved closed etc, add the code instead to the ThisWorkbook code window (although you'd have to alter the code slightly as 'Me' is referencing the particular worksheet in which the code is placed).

What is the function to return the name/address of a cell or range (Spreadsheet)?

I could not find the function that returns the name of the cell referenced. For example, =SOMETHING(A5) that will return A5 as string.
So that, I can write ="For more information, see " & SOMETHING(F50) & "." in a cell and the cell will read For more information, see F50., and then, when I move the F50 cell, the text will also change.
So, what is that SOMETHING?
If it works for Google Spreadsheet it's the best, but if you are not familiar with Google Spreadsheet, OpenOffice Calc and MS Excel solutions are most probably compatible too.
In Excel you can use the ADDRESS function.
In Excel you can also use the CELL function.
="For more information, see " & CELL("address",F50) & "."
will return
For more information, see $F$50.
An alternate is to create a hyperlink to the location based on the CELL function. It will be easier for the end user, but the formula is more complex.
=HYPERLINK((MID(CELL("filename",F50),4,255)&"!"&CELL("address",F50)),"For more information click here.")
this will return
For more information click here.
and when it is clicked on, the cell specified will be selected.

Resources