converting excel spanish dates - excel

I have spreadsheet with mutliple rows in which a few are dates. The problem is that while some rows are in english date format, few others are in spanish format eg. Octubre 1, 2015, Septiembre 1, 2014 etc. What could be the easiest way to convert all of them into english format dates.

Give this small macro a try:
Sub Converter()
ary = Split("Enero, January, Febrero, February, Marzo, March, Abril, April, Mayo, May, Junio, June, Julio, July, Agosto, August, Septiembre, September, Octubre, October, Noviembre, November, Diciembre, December", ", ")
For I = 0 To 23 Step 2
Cells.Replace What:=ary(I), Replacement:=ary(I + 1)
Next I
End Sub

The following sub will select all cells containing dates (irrespective of how they are formatted) on the active sheet. If you run it and then right-click on one of the selected cells and select format cells from the drop-down menu, you can decide on a common date format:
Sub SelectDates()
Dim dates As Range
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If IsDate(cell.Value) Then
If dates Is Nothing Then
Set dates = cell
Else
Set dates = Union(dates, cell)
End If
End If
Next cell
dates.Select
End Sub

Related

How to display only year in vba?

I have the following data set in general formatting.
Bunch of years with no day nor months provided.
What I want to achieve, is to display the date in yyyy format.
I made a standard DateSerial function to convert the data to date properly.
Private Function toDate(ByVal text As String) As Date
toDate = DateSerial(Int(text), 1, 1)
End Function
For Each cell in ws.Range("A21:A" & lr)
cell = toDate(cell)
cell.NumberFormat = "yyyy"
Next cell
Now, technically this works, but if you click inside the cell, it
obviously shows the date only as 01-01-year - that is to be expected
with usage of dateserial
But I was wondering, would it be possible given my data to somehow
omit the Days and Months and only display the result as a year?
Basically, I need want to convert the data to a Date data-type without specifying days and months
Entering the years and formatting the date as "YYYY" could be done like this:
Sub TestMe()
With ThisWorkbook.Worksheets(1)
.Range("A1") = 2011
.Range("A2") = 2013
.Range("A3") = 2011
Dim myCell As Range
For Each myCell In .Range("A1:A3")
myCell = DateSerial(myCell, 1, 1)
myCell.NumberFormat = "yyyy"
Next myCell
End With
End Sub
The "trick", is that DateSerial(myCell, 1, 1) takes the year from the cell and adds 1 for day and January for month. Thus, every year is represented as the date 1.January from that year.
More about the Date in VBA and Excel - VBA doesn't return the correct Date with Now()

Excel - Freezing a Calculated Date Until The Date Itself Has Passed

Is it possible to have Excel freeze a calculated date until the calculated date itself has passed?
Within the Excel example below, Today's Date is formulated with TODAY(), and Next Proposed Meeting is a calculated date by adding Today's Date plus Meeting Cadence.
Excel Example:
Here is what I'm looking to do: when a user opens the workbook and sets the initial meeting cadence, I would like to freeze the Next Proposed Meeting date until that specific date meets the date referenced in today's date.
(Example: today's date is Monday, October 1, 2018 and the next proposed meeting date is Monday, October 1, 2018).
When the two dates match, I would like it to cycle to the next date, depending on the numerical value of the cadence. So, if the meeting cadence continued to be 7 days, the Next Proposed Meeting cell would automatically populate to "Monday, October 8, 2018."
What would be the best way to accomplish this?
Cheers, and thank you!
:)
Hacked this out.
In a module:
Sub setCurrentProposedDate(cadenceChanged As Boolean)
Dim currProposedDate As Name, currCadence As Name
Set currProposedDate = ThisWorkbook.Names.Item("CurrentProposed")
Set currCadence = ThisWorkbook.Names.Item("CurrentCadence")
If cadenceChanged Then
currProposedDate.Value = Sheet1.Range("B2").Value - Evaluate(currCadence.Value) + Evaluate(currProposedDate.Value)
currCadence.Value = Sheet1.Range("B2").Value
End If
If Sheet1.Range("B1").Value - Evaluate(currProposedDate.Value) >= 0 Then
currProposedDate.Value = Sheet1.Range("B2").Value + Evaluate(currProposedDate.Value)
End If
End Sub
In workbook module:
Private Sub Workbook_Open()
setCurrentProposedDate False
End Sub
In Sheet1 module:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Sheet1.Range("B2")) Is Nothing Then
setCurrentProposedDate True
End If
End Sub
Set workbook level names to be :
Put this formula in B3:
=CurrentProposed
Here is a stab at doing that via formula...
- Set a Project Start Date such as Monday, 3 September, 2018 in B1
- Enter your cadence value (7, 10, 14, etc.) in B2
- Formula for "Next Meeting" in B3 is =SUM(B1,PRODUCT(ROUNDDOWN(DAYS(TODAY(),B1)/B2,0)+1,B2))
Explanation:
- The Rounded down value of the date difference between two dates (Start Date and Today) gives you a whole number indicating the number of periods (based on cadence) you are after the start
- Add one to that b/c you want to predict the next meeting date
- Multiply that by the cadence to get the number of days until next meeting date (from the start)
- Modify the cadence (B2) and your next meeting date should adjust appropriately.
I tested with my project and a few random dates and cadences and it seems to work.

How to get Column and row number of a calendar date

How to get Column and row number of a calendar date in excel?
Eg. Suppose my date is 26-May-17 so I should get rownumber=5 and column number=5
As I understand you are having dates from Jan1 in cell A1 till Jan 31 in cell A31 and similarly Feb1 in cell B1 till Feb 28 in cell b28, So this way you can use the below code.
Sub test()
MsgBox ActiveCell.Address(0, 0, xlR1C1)
End Sub

Converting all dates in a year into multiple strings using Excel VBA

I have to write a vba code that convert all dates in a year into days in a week eg. Monday, Tuesday, Wednesday....Sunday and the value of all days in a week eg.Monday must be in a string format. (See image inserted)
I tried using the .NumberFormat function but it does not work since the format is still under the date format although the values displayed are correct (please look at the formula bar of F10). Below is the code I have written:
Sub convertdate()
Range("A7:A371").Copy
'copy all the dates throughout the year'
Range("F7:F371").PasteSpecial xlPasteFormulasAndNumberFormats
'paste it into F column'
Worksheets("Sheet1").Range("F7:F371").NumberFormat = "dddd"
'convert the dates into days'
Sum1 = Application.SumIf(Range("F7:F371"), "Monday", Range("B7:B371"))
'example of calculating the total rainfall of all Mondays throughout the year'
Worksheets("Sheet1").Range("G22").FormulaArray = Sum1
End Sub
The formula bar from cell F7:F371 should display the string value "Monday","Tuesday" etc depending on the dates rather than the date itself.The reason of converting it into a string is so that it could be use in a SUMIF function later on to calculate the total rainfall of all Mondays,Tuesday etc.
Appreciate if anyone could help. Thank you.
A formula can do this.
In cell F7 enter =TEXT(A7,"dddd") and drag down.
This will format the date to show the full day name as a string.
https://support.office.com/en-us/article/TEXT-function-20d5ac4d-7b94-49fd-bb38-93d29371225c
Try something like this. It will loop through all the dates in Column A (starting in row 7) and put the associated Weekday name in Column F:
Sub test()
Dim i As Long
Dim lRow As Long
With ActiveSheet
lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 7 To lRow
.Cells(i, 6).Value = WeekdayName(Weekday(.Cells(i, 1).Value, 1), False, 1)
Next i
End With
End Sub

VBA or Excel Macro to add 1year

I have an Excel Spreadsheet that I want to add 1 year to the date in a cell.
Cell B3 currently has a value of 1/1/2014
Would like to create a Macro that will change this date to 1/1/2015
Seems easy enough but my search for this have not given desired results. Any help would be appreciated.
Select your cell and run:
Sub dateFixer()
Dim d As Date
d = ActiveCell.Value
ActiveCell.Value = DateSerial(Year(d) + 1, Month(d), Day(d))
End Sub

Resources