EXCEL - dropdown and fill cells - excel

Good night.
I'm having some troubles to get what i need done.
I have some cells in a sheet that needs to be filled every day, manually.
I have also a dropdown with all the months, and another one with the days.
Is it possible to save data in specific cells for the selected dropdown values?
Something like for each day mantain different data in the same cells.
Thanks.

I'm not exactly sure what you are requesting. What I think you are trying to do is:
Enter something into a cell
Select the Month and Day from the dropdown lists
Record the value of the dropdowns into cells near the value you entered.
Is this correct? If so, you would need to need to write a VBA macro that would take the values of the dropdown and write them into the cells where you needed them to be (presume next to your entered text). I think this would do that for you.
Sub writeDropdowns()
'This will take the values from cells B1 and C1
'and record this in the two cells next to the selected cell
Selection.Offset(0, 1).Value = ActiveSheet.Range("B1")
Selection.Offset(0, 2).Value = ActiveSheet.Range("C1")
End Sub
It assumes that the dropdown values are in cell B1 and C1 of the same sheet.You could then link this macro to a Form button. This is very simple and doesn't check for any errors, like if there is no cell selected. It should be a good starting point though.

Related

How to populate combobox dropdown in userform from Excel data?

How do I populate a combobox in a userform with the values in an Excel sheet?
Say sheet name as "Reg ALL - current".
I need to populate the value from cell AI (which is a date column).
Also I need to increment the date one day from AJ to cell BF.
Example: if AI holds value (19/06/2019) then AJ should hold (20/06/2019) and so on until BF.
There are different ways. If you have one set range of cells (that's what I assume reading your question) that won't change, you could just set the RowSource property of your combobox.
For example:
Apply to your situation:
Cell AI1 holds your date
Cell AJ1 holds formula =AI1+1
Drag formula to cell BF1 (assuming you always want to add to the value in AI1, the formula will keep doing this for you)
Use RowSource property and fill in =Sheet1!AI1:BF1
Conclusion, no VBA needed at all! If I understood your question well enough that is.
Here is simple solution
Just add a button, paste this.
Dim i As Long
'Clear existing items
ComboBox1.Clear
'36 (AJ) column to 58 (BF) column
For i = 36 To 58
ComboBox1.AddItem ActiveSheet.Cells(1, i).Value
Next i

VBA macro in excel that will copy and paste a range of cells into another sheet weekly

I am very new to VBA but have a need use it in a report I run weekly. There are six columns that I need to copy and paste into another sheet each week - this would be cumulative so it would paste the new data after the old data each week, not replace it. The range for this case is A6:A24 through F6:F24. One additionally caveat is that I would like to add one column called date that posts that days date - is that doable? I have attached a snippet - my idea is to create the column headers in the new tab (manager, employee, etc.) and fill data down each week so I can create a chart with historical data.
Adding what I have come up with:
Sub sbCopyRangeToAnotherSheet()
'Method 1
Sheets("Summary Build").Range("A6:F24").Copy Destination:=Sheets("Sheet1").Range("A2")
End Sub
You were nearly there. Your code will copy to A2. To find the next blank cell you need to start at the bottom of the spreadsheet, go up to the first filled cell and then down one. Bottom of the spreadsheet is range(sheet.rows.count,1) To go up we use End(xlup) and then down one .offset(1,0) That's One row, no columns. Put it together and we get range(sheets("sheet1").rows.count,1).end(xlup).offset(1,0)
So your line is
Sheets("Summary Build").Range("A6:F24").Copy Destination:=range(sheets("sheet1").rows.count,1).end(xlup).offset(1,0)
To put today's date into a cell you can use the date function eg:
Range("A2") = Date()
EDIT: Sorry it should read
Sheets(1).Range("A6:F24").Copy _
Destination:=Sheets("sheet1").Cells(Sheets("sheet1").Rows.Count, 1).End(xlUp).Offset(1, 0)

Getting adjacent cell values around the current cell in Excel VBA

I want to get the adjacent cell values for calculation in VBA.
It is easy to get the left cell of the current cell(e.g.H19) usually like this:
=H18
If I copy this cell to other cells, each of them is changed to an appropriate cell number.
But in VBA code, I am not sure if I am right to get the value of the left cell.
Public Function LeftCell()
LeftCell = ActiveCell.Offset(0, -1).Value
End Function
I am not sure this is correct, I tested copying this cell to other cells but each result is not changed automatically.
I clicked all kinds of Calcuation buttons on the Menu, changed Calculation as Automatic, but there is no calculation occur.
The only way I can do is to manually select each cell and press enter.
Is there any way to calculate all cell values?
Otherwise, "The Active Cell" means "The Selected Cell by Cursor"?
Thanks for your help in advance.
Adding a formula as #Chris Harper suggests would work, but then you may as well just write the formula in the cell.
Rather than the ActiveCell you want the cell that called the formula.
Public Function LeftCell()
LeftCell = Application.Caller.Offset(, -1).Value
End Function
Edit: If you want the cell to update whenever you change the value add Application.Volatile True as your first line in the function.
https://msdn.microsoft.com/en-us/library/office/ff193687.aspx
Calculate method in Excel VBA do all kind of calculations. You can even define a range to calculate only a range of specific cells like Worksheets("Sheet1").Calculate.
Yes, ActiveCell is always the Selected Cell.
As an alternative to setting value by Offset, you can use ActiveCell.FormulaR1C1 = "=RC[-1]"

Copy specific cells from one row and paste into different cells on another worksheet

I saw many similar questions on this site but non of them has answer. Not sure why. Probably it is too simple to bother. Not for me though. I am not good at all with VBA and will not probably need to pick on it for another number of years. Hopefully someone will be kind to spend time and help.
I have two sheets in a workbook. Sht1 contains data organized by rows. Rows populated daily, total number of rows will be 300 to 400 by the end of project. Sht2 represents a document form. Most of the cells on that form contain static information that does not change from one report to another. Except some dynamic cells that have to be populated from Sht1. I print the form and file the hard copy. I might come back and print some reports one more time if the hard copies gone missing or the data changed for some reason. The point is clear - I do not want to keep and manage 400 Word files. It is just painful.
What I wanted is assign a code to a command button which will call for an input box. I enter the row ID (I guess the rows should be numbered consequently from 1 to N). Then VBA takes data from some cells of that row, lets say C5 (when ID=4), E5 and H5 on Sht1 and copies them to cells B5, D5 and D7 on Sht2.
Much appreciated for your time reading this and even more if you can help.
Thank you.
Here is some very simple code to copy data from one cell on Sheet1 to another cell on Sheet2.
Sub Macro1()
Dim iRow As Integer
iRow = InputBox("Which row?")
Worksheets("Sht2").Cells(5, 2).Value = Worksheets("Sht1").Cells(iRow, 3).Value
Worksheets("Sht2").Cells(5, 4).Value = Worksheets("Sht1").Cells(iRow, 5).Value
Worksheets("Sht2").Cells(7, 4).Value = Worksheets("Sht1").Cells(iRow, 7).Value
End Sub
This takes values from the row specified on Sheet1, columns C, E, and H.
It copies these values onto Sheet2, cells B5, D5, D7, respectively. Note the order of arguments to Cells(row, col), which is opposite to the Excel cell references that you would be used to. In other words, remember that Cells(1, 3) is actually C1.
This is about as simple as I can make it but it should set you in the right direction.

Excel Formula which places date/time in cell when data is entered in another cell in the same row

Hoping there is a way this can be done with a formula since I will be putting this on SharePoint as a shared workbook.
Column B contains Tasks, while Column E contains the Date and Time of when the Task was assigned. Is there a formula that would automatically enter the current date and time in Column E whenever someone entered data into column B?
Any assistance would be greatly appreciated.
Another way to do this is described below.
First, turn on iterative calculations on under File - Options - Formulas - Enable Iterative Calculation. Then set maximum iterations to 1000.
The 1000 iterations doesn't matter for this formula, but it stops excel getting stuck in an infinite loop for other circular references.
After doing this, use the following formula.
=If(D55="","",IF(C55="",NOW(),C55))
Once anything is typed into cell D55 (for this example) then C55 populates today's date and/or time depending on the cell format. This date/time will not change again even if new data is entered into cell C55 so it shows the date/time that the data was entered originally.
This is a circular reference formula so you will get a warning about it every time you open the workbook. Regardless, the formula works and is easy to use anywhere you would like in the worksheet.
This can be accomplished with a simple VBA function. Excel has support for a Worksheet Change Sub which can be programmed to put a date in a related column every time it fires.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target.Offset(0, 3).Value = "" Then
Target.Offset(0, 3) = Format(Now(), "HH:MM:SS")
End If
End Sub
A quick explanation. The following "if" statement checks for two things: (1) if it is the second column that changed (Column B), and (2) if the cell 3 columns over (Column E) is currently empty.
If Target.Column = 2 And Target.Offset(0, 3).Value = "" Then
If both conditions are true, then it puts the date into the cell in Column E with the NOW() function.
Target.Offset(0, 3) = Format(Now(), "HH:MM:SS")
Range.Offset
Range.Column
Not sure if this works for cells with functions but I found this code elsewhere for single cell entries and modified it for my use. If done properly, you do not need to worry about entering a function in a cell or the file changing the dates to that day's date every time it is opened.
open Excel
press "Alt+F11"
Double-click on the worksheet that you want to apply the change to (listed on the left)
copy/paste the code below
adjust the Range(:) input to correspond to the column you will update
adjust the Offset(0,_) input to correspond to the column where you would like the date displayed (in the version below I am making updates to column D and I want the date displayed in column F, hence the input entry of "2" for 2 columns over from column D)
hit save
repeat steps above if there are other worksheets in your workbook that need the same code
you may have to change the number format of the column displaying the date to "General" and increase the column's width if it is displaying "####" after you make an updated entry
Copy/Paste Code below:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("D:D")) Is Nothing Then Exit Sub
Target.Offset(0, 2) = Date
End Sub
Good luck...
I'm afraid there is not such a function. You'll need a macro to acomplish this task.
You could do something like this in column E(remember to set custom format "dd/mm/yyyy hh:mm"):
=If(B1="";"";Now())
But it will change value everytime file opens.
You'll need save the value via macro.
You can use If function
Write in the cell where you want to input the date the following formula:
=IF(MODIFIED-CELLNUMBER<>"",IF(CELLNUMBER-WHERE-TO-INPUT-DATE="",NOW(),CELLNUMBER-WHERE-TO-INPUT-DATE),"")
Here is the solution that worked for me
=IF(H14<>"",NOW(),"")

Resources