Autofill excel date after entering month of - excel

I am creating an excel template and want to auto populate the dates in my table.
Above their is a line where the dates included are written in EX. 10/01/14 - 10/31/14.
I want the dates in my table to be filled in when i enter those dates.
Do I need to make it two cells, one start date and one end date?
What formula do i need to use?

Select the cell containing the pair of dates separated by a dash and run this small macro:
Sub DateMaker()
Dim v As String, d1 As Date, d2 As Date, i As Long
v = ActiveCell.Text
ary = Split(v, "-")
d1 = DateValue(Trim(ary(0)))
d2 = DateValue(Trim(ary(1)))
Set r = ActiveCell.Offset(1, 0)
For i = 1 To Rows.Count
r.Value = d1
d1 = d1 + 1
If d1 > d2 Then Exit Sub
Set r = r.Offset(1, 0)
Next i
End Sub

If you can manage without using the Table then Try This:
select entire entry range (blank cells where date would reside later) and insert this formula :
=LEFT($L$3;8)+(ROW()-n)
here, n= row no of first entry and L3 cell contain the date range.
After pasting the above formula press CTRL+SHIFT+ENTER to make it array formula.
Or, you might follow the macro (code) way suggested in previous answer.

2 cells are the easiest - you can then CONCATENATE them to give the display how you want, and hide the Start and End columns
In the first (start) cell, put your starting date.
For the ending date, use =EOMONTH([#Start],0)
For 2nd month use either =DATE(YEAR(A2),MONTH(A2)+1,1) or =B2+1 as the start date, and keep =EOMONTH([#Start],0) as the end date. The table will then autofill with the start and end date for each month as you grow the table.

Related

How to fill blank cells in Excel with the date of 30/06/YEAR by picking the year from the cell in the next column

Consider the following table:
I have a series of blank cells with missing data. From this missing data I only have the year in the next column. I need to fill any blank cells with a standard day/month of 30/06. The year of each cell however needs to be the year in the next column. The attached file shows how my data is arranged. So at cell B 2091, the date shall be 30/06/2011 while for cell B 2098 the date shall be 30/06/2018 and at cell B 2100 the date shall be 30/06/2008.
Filter on the blank cells in column B. Then, in the topmost cell (which I'll assume to be B1 but will likely be different), enter a formula similar to the following and fill down
=DATE(C1,6,30)
where the row number in C1 is the same as your first row of data.
You can achieve this with a helper column (any blank column in the same worksheet where you need the dates). In that column enter this formula in the first cell (here in row 2) and copy down.
=IF(ISBLANK(B2),DATE(C2,6,30),B2)
Then copy the Values from the helper column to the date column and delete the helper.
Below is a small macro that is doing the same job. It needs no helper column and over-writes your existing blanks. Before you run it make sure to check the values of the 2 constants at the top and the name of the worksheet (especially the latter!) against your requirements.
Sub WriteStandardDate()
'293
Const FirstDataRow As Long = 2 'change to suit
Const DateClm As Long = 2 'change to suit
' year column must be adjacent to DateClm
Dim R As Long
Dim Arr As Variant
Dim Rng As Range
With Worksheets("Sheet1") ' change name as required
Set Rng = .Range(.Cells(FirstDataRow, DateClm), _
.Cells(.Rows.Count, DateClm).End(xlUp)) _
.Resize(, 2)
Arr = Rng.Value
For R = 1 To UBound(Arr)
If IsEmpty(Arr(R, 1)) Then
Arr(R, 1) = DateSerial(Arr(R, 2), 6, 30)
End If
Next R
Rng.Value = Arr
End With
End Sub
Update: I used the formula suggested by Variatus: =IF(ISBLANK(B2),DATE(C2,6,30),B2) and worked fine through a helper column. There was no need to copy / paste the new dates into the Dates column. I just used the helper column as the new Dates column since full dates from the original column were not changed and got inserted in the helper column thanks to the IFBLANK portion of the formula. Thanks.

Change the value of a column with vba code rather than loop

I want to add "#" before each cell in a column (have more than 13000 cells), and add "000" to another column through vba excel code. I can achieve this with loop but it takes a long time when running the macro. Can anyone help me with more effective solutions?
for each cell in column
cell = "#"& cell
next cell
for each cell in column
select case len(cell)
case 2: cell = "'000" & cell
case 3: cell = "'00" & cell
end select
next cell
Desired result:
456 => #456
10 => 00010
however it runs very slowly.
Use display format:
Range("A1:A1300").NumberFormat = "\##"
Range("B1:B1300").NumberFormat = "00000"
This does not change the underlying value, but it will display correctly.
To read the value out use Cell.Text to retrieve a string with the leading zeros.

How put date in Column A when i fill a cell in column B? Excel

i have that problem, when a guy complete cell 1 from column B i want to put date now in Column A, cell 1. If i save excel I want to save date, if i open tomorrow to save date from the last day but when complete Column B, row 2, put date from the current date without change date from Column A, row 1. Like in picture:
Ex: if i complete in Column B, row 6, put current date in Column A, row 6, without change other dates.
Thanks
Only way I know of that you can do this is with some VBA code.
Select the sheet that you want to automate and press ALT + F11 to go to the VBA editor, then you could use some code like this
Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Column = 2) Then ' Check if in 2nd Column ie. Column B
If Target.Offset(, -1).Value = "" Then ' Check if there is already a value in Column A
Target.Offset(, -1).Value = Date ' No value, lets stick in the current system date
End If
End If
End Sub
Problem with this code is it will run for every cell change and on a large workbook might slow things down a bit.

Take current date issue

I have two cells A1 and A2. What I want is for A1 to take the current date mm/dd/yyyy if A2 has a value bigger than zero (0). For this I used the following formula in A1:
=IF(E2>0;(TODAY()))
So if a cell in A2 is for example 60 then A1 will be 11/03/2015.
If I save this and reopen it the next day the values in A1 will automatically change into the new date. This is something that I don't like as I want to use this method to keep track of my expenses each day. So if I type an amount in A2 I want A1 to give me the current date and keep it.
So how can I get the current date without worrying that every time I reopen the file they will change?
What you're looking for is a macro, not a formula. I am assuming you're performing this operation on COLUMNS not ROWS. EG: A1 and B1, NOT A1 and A2.
What is the difference?
Macro: Can be triggered one time on an event.
Formula: Given a input, it constantly re-evaluates the result.
Step 1) Press Alt+F11, this will open up the code editor in VBA.
Step 2) Copy and paste the code below into your 'sheet' that your formula resides in.
Step 3) Save your workbook as a macro-enabled spreadsheet. (xlsm).
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
If (Target.Columns.Count = 1 And Target.Column = 2 And Target.Rows.Count = 1) Then
'Check every row, currently this will get executed once
For Each cell In Target.Cells
'Make sure the value is a number
If (IsNumeric(cell.Value)) Then
'Make sure the value is greater than 0
If (cell.Value > 0) Then
'Check to make sure the date column is empty, so it only ever gets written once
'Note: You can remove the if statement below, if you want it to get re-evaluated every time you make a change
If (Target.Worksheet.Cells(cell.row, 1).Value = "") Then
'Using the current modified row, set column 1 to Today
'Note: Now() is the same as Today in VBA
Target.Worksheet.Cells(cell.row, 1).Value = Now()
End If
End If
End If
Next cell
End If
End Sub
Note: This macro only gets executed if you modify one row at a time, you can change it to work on multiple cells by removing the 'Target.Rows.Count = 1' part of the FIRST 'if' statement.
Note2: The last nested 'if' statement can be removed if you want the date to be re-evaluated any time a change is made to column 2. (aka Column B, in VBA columns are referenced via number, not letters).
Note3: If you really need it to work via rows, try to understand this macro by stepping through it with the debugger, and reconstruct it. Keying off of Rows instead of Columns.

VBA - Enter a formula into all active rows of the current column (when you don't know the column letter, or if the column changes)

Hi guys this is my first post, I'm wondering if you can possibly assist me.
I'd like to write a macro / script that will allow me to put a formula into the column to the right of the currently selected one (for all active rows of the current column) based on what column I've selected. The issue I'm having is that I don't always know the current column letter (as my selection changes from worksheet to worksheet).
To give you an example:
One of my columns currently contains dates, that dates are entered in different formats though, some are separated with ".", some with "-", some with spaces and so on. I have a formula that will deal with this so I need to put this formula in the column to the right of the selected column (which has the dates).
I have been able to do this when I specify the column letter, but not if it changes.
Please can you help?
Give this a go,
Sub SomethingNeat()
Dim rng As Range, x
x = Selection.Column
On Error Resume Next
Set rng = Columns(x).SpecialCells(xlCellTypeConstants, 23)
If Not rng Is Nothing Then rng.Offset(, 1) = "'=MyFormula"
End Sub
You can use ActiveCell.Offset(0,1).Value = Variable
That means that whetever your current cell is you can move and "select" to put a value to the right cell of the one you have activated. You can move the selection using a loop.
Do
Workbooks("Yur workbook name").Worksheets(1).Range(Adress you want to start adding).Offset(0, 1).formula = "=FORMULA"
i = i + 1
ActiveCell.Offset(1, 0).Activate
Loop While i <= max_row
Edit: 2nd
Put the formula in a cell lets say C1
'Select a range
Set take = Worksheets(1).Range("C1")
take.Copy 'copy the formula
Worksheets(1).Paste Destination:=Worksheets(1).Range("B1:B10")
That will copy your function whenever you want it to

Resources