ctkoh
December 16, 2022, 10:22am
1
Hi, i need help with what VB expression should i use if i’d like to:
check if an excel cell is formatted as a date (dd/mm/yyyy hh:mm AM/PM) format.
Am intending to use this expression inside an IF statement.
IF a cell is not formatted as a date… THEN… (format it as date)
ELSE… (ignore)
Thanks in advance!
Hi @ctkoh
DateTime.TryParseExact(strinput.ToString,“MM/dd/yyyy hh:mm:ss”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing)
Inside if use this condition if it is true then leave it otherwise in else section.
Anil_G
(Anil Gorthi)
December 16, 2022, 10:30am
3
Hi @ctkoh
To be exact with your format.please use this
DateTime.TryParseExact((“Excel date string”, “dd/MM/yyyy hh:mm tt”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing)
And for formatting you can use format cell
Cheers
ctkoh
December 16, 2022, 10:31am
4
sangeethaneelavannan1:
DateTime.TryParseExact(strinput.ToString,“MM/dd/yyyy hh:mm:ss”, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Nothing)
Hi! Thank you for the fast reply!
Just wondering how do I use this VB expression to check a specific cell in my xlsx file.
I don’t see it referencing any excel file or cell.
Anil_G
(Anil Gorthi)
December 16, 2022, 10:32am
5
@ctkoh
Use for each row in excel then get the value and use the value in place of string
Currentrow("datecolumn").tostring.trim
inside loop this is how you get the date string
Cheers
For each row in datatable inside currentrow(index of column).tostring will be you input string in the above code
ctkoh
December 16, 2022, 11:02am
7
Thank you so much for the quick advice everyone!
With your help i managed to get the solution.