I am currently studying VBA programming, and faced with a situation in which I would appreciate your help. Ideally, not just finding a solution, but also understanding how and why the solution works.
Say there is a database from which you can export a data spreadsheet. One of the columns has date values, but they are poorly formatted from export. The system sends dates as mm / dd / yyyy hh: mm AM / PM, for example, 04/11/2014 09:24 AMbut the table has this designation as dd / mm / ..., which means that it enters 04 as the day and 11 as the month.
In this column, if the day precedes or includes 12 months, the cell is formatted as a date. If the day has passed on the 12th, the cell is formatted in a common format.
My question is: can I write a VBA macro that could change the day and month values ββand create the correct dates in a new column? I would think that first you need to determine if the cell is formatted as a date, and then somehow display the date and month in the correct positions or format it as a common format, and then use a different code to extract the correct date.
If this is too common a problem for this community and another community is more suitable there, I will gladly post my question there.
EDIT:
After my comment below, I played with functions and searched for other similar functions that can help do what I need, switch the day value with the month value, and so far I have:
'for dates with general format: 04/14/2014 11:20 AM
=DATE(MID(A1,7,4),LEFT(A1,2),MID(A1,4,2)) 'in a column for the date
=TIME(MID(A1,12,2),MID(A1,15,2),"00") 'in a column for time, since I may need this
'for dates with a date format: 4/11/2014 7:35:00 PM
=DATE(TEXT(A1,"yyyy"),TEXT(A1,"dd"),TEXT(A1,"mm")) 'in a column for the date
=TEXT(A1,"hh:mm AM/PM") 'in a column for time
, , A.
VBA? , , , . - VBA "", . , , - .
EDIT2:
, . , , FIND , , IFERROR Excel, = IF.
'to get the correct date
=IF(IFERROR(FIND("/",A1),0)>0,DATE(MID(A1,7,4),LEFT(A1,2),MID(A1,4,2)),DATE(TEXT(A1,"yyyy"),TEXT(A1,"dd"),TEXT(A1,"mm")))
'to get the correct time
=IF(IFERROR(FIND("/",A1),0)>0,TIME(MID(A1,12,2),MID(A1,15,2),"00"),TEXT(A1,"h:mm AM/PM"))
, , , VBA .