Excel, Add auto Sequence number - excel

I need to ad the next sequence number in Column A automatically when I fill enter the next value in Column B. This sounds confused. Just see the snap so you will get the clear picture.
This should be done without usual dragging option. Is there any way

Make the Value of A1 equal to 1 and then from the A2 use the formula:
=IF(B3<>"",A2+1," ")
Drag this formula for the whole column.
In my solution I have a drag, but it is to define the formula for each of the fields. (I'm not sure if is this you are trying to avoid when you say
without the usual dragging option
)

You may achieve this using macros. Formula will increase the file size and processing time.
Right click on the sheet name on sheet tab-->select view code-->paste below code--> save file as macro enabled workbook.
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo step
If Target.Column = 2 And Target.Value <> "" Then
Target.Offset(0, -1) = Target.Row - 1
End If
Exit Sub
step:
Exit Sub
End Sub

You can also do this without using macro and formula:
Type first 2 value to the cell to establish the pattern
highlight the cell range
Under Home tag -> select Fill -> choose Series
Follow the image and Select OK

If you convert your table to a List ("Table") and use a formula for the first column, that formula will "auto-extend" as new values are typed in under "Item"

Related

Excel selecting a number of cells below selected cell shortcut options

In Excel, I would like to select a cell and then copy the contents to n number of cells below. Instead of using the "fill" drag option since the number of rows will be fairly large and require scrolling and then stopping at the correct cell I was looking for other options.
I am currently doing the the following:
In excel I select a cell and then on the top left corner it shows the cell (i.e. A1). Then to select the number of cells below it, I modify the top left box to a range such as A1:A10 which selects the range of cells. See attached image. I then use the shortcut key "Ctrl-D" which copies the first cell to the other cells.
Is there a way instead of mentally calculating the ending cell number, I can do something that effectively works "A1 + 10" in this box to select 10 cells below to select the A1:A10 range?
How about this way? Enter your formula in cell 1. Enter the number of copies (including the original) you want of it in the cell below it. Double-click on the number you entered and the formula is filled down.
To try, install the procedure below in the code module of the worksheet on which you want the action. (That's a module Excel set up when you created the sheet. Don't install the code in a standard code module that you have to insert yourself.)
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Const TriggerClm As String = "A"
Dim R As Long
With Target
If (.Column = Columns(TriggerClm).Column) And (.Row > 1) Then
R = Val(.Value)
If R Then
With .Offset(-1)
If .HasFormula Then
.Resize(R).FillDown
.Select
Cancel = True
End If
End With
End If
End If
End With
End Sub
You may wish or have to tweak the code. For example, the action is limited to column A. Change the constant at the top of the code to identify the column you prefer, or change the limits to better suit your requirements. The code also checks if Cell #1 contains a formula. If that isn't what you want to fill down that condition will have to be revised.
Last, but not least, the code selects Cell#1 (the one that contained the number is over-written). That may not be the best choice. You can modify the code to select a place in your worksheet where you will continue working.

Solve for value without using Solver

I currently have the following in excel for other users.
The Number column does not change. Users will input values in Multiplier 1 and Multiplier 2 columns and they will get a value in Outcome column.
Is there an automatically way where the user can also input a value in Outcome column and the Multiplier 1 column will change?
Currently Number and Outcome column are protected, will I need to unprotect the Outcome column?
I recommend you use some VBA code using the Sub Worksheet_Change(ByVal Target as range) in the worksheet.
If the user enters a value in D2 it will put the formula "=D2/(A2*C2)" in B2
If the user enters a value in B2 it will put the formula "=A2*B2*C2" in D2
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.Count > 1 Then Exit Sub
On Error GoTo LastLine
If Not Intersect(Target, Range("D2")) Is Nothing Then
Range("B2").Formula = "=D2/(A2*C2)"
ElseIf Not Intersect(Target, Range("B2")) Is Nothing Then
Range("D2").Formula = "=A2*B2*C2"
End If
LastLine:
Application.EnableEvents = True
End Sub
This can be done. Begin by noticing that your formula is so simple that you
Can easily solve for multiplier1 as a function of:
outcome divided by (number times multiplier2)
Next get tricky by adding a 1 pixel wide column that will contain your formula
for outcome to the right of (now an input not a formula) the original
outcome column.
Similarly add a 1 pixel wide col to the right of multiplier1 that contains
your new formula for multiplier1. Adjust data validation on original input
cells for multiplier1 and outcome to allow only one of the two to be
entered at a time (use isblank function appropriately in an excel custom data
validation rule for each cell).
Finally right align the two 1 pixel wide cells so that their calculated values
appear within the corresponding enterable cells when they are blank.
Yes it's tricky but it works.
Sorry this is just an outline but I have used this in an application and it
works great. No vba, so undo redo don't break. Try it you'll like it.

Excel VBA - Select a cell in a highlighted range

Is it possible to select a specific cell in a range that changes depending on what cells are highlighted.
So if i Had;
Range("C1").Value = Application.WorksheetFunction.Sum(Selection)
It would sum the entire highlighted area and put the value in C1. Is it possible to only select some cells in the highlighted area. I know it sounds dumb, i realise can just highlight the cells i need but this is just a simplified version of the problem I've got.
What i'm asking is, is there a way in code to say;
"In the highlighted range, select the cell that is 2 columns to the right and 4 columns down from the top left boundary of the range"
Thanks
The Code for your question:
"In the highlighted range, select the cell that is 2 columns to the right and 4 columns down from the top left boundary of the range"
Selection.Cells(1).Offset(4,2).Select
in your case being Selection a Range you can use its methods/properties:
Range("C1").Value = Application.WorksheetFunction.Sum(Selection.Cells(5,3))
since Cells(5,3) reference a cell 2 columns to the right and 4 rows down offset the selection top-left one
You may be able to use the Worksheet_SelectionChange Event and examine the Target reference.
For example paste this test code into some sheet class:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "A1" Then Exit Sub
Range("A1").Value = WorksheetFunction.Sum(Target)
End Sub
Something like this - obviously you're going to have all kinds of checks in there for Errors and the likes.
I'd also look at some way of disabling the code since you're going to have Events firing all over the place. Depends on your requirements.

Display value (result of formula) rather than formula in fomula bar

Here is the problem:
My table is very large and the column width is not enough to show all the text in it.
Since the text/value is generated by a formula in the cell, if I click on the cell, the Formula Bar will display the formula and not the value. Of course.
However, I think it is very useful to quickly know the content of the cell generated by the formula. If I expand the column width every time is not quick and clean.
Do you know if there is a way to solve the problem?
No there is not a way to show it in the formula bar if there is a formula in the cell.
The best thing I can suggest is to leave row 1 empty and merge A1:N1 together or similar, ,freeze row 1 if necessary
then put this formula into A1
=INDIRECT(CELL("address"))
When you select a cell on the sheet , press F9 on the keyboard and you can read the full value of the active cell in row 1
With a little VBA in the sheet you can also have it automatically update the cell
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Calculate
End Sub
Here's another solution. Simply assign a key to the following macro:
Sub DislayCellValue()
Dim outp As String
outp = "The value in the active cell is:" & Chr(13) & Chr(13) & ActiveCell.Value
MsgBox Prompt:=outp
End Sub
To display the value in a cell, click on the cell and hit Ctrl-(key).This might be helpful.

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