is there is any formula to have the input time of B1 in A1..
or in row A1 how to get the exact time of input of B1..
.is it possible by excel formula
Dont know any way to do it with formulas, but you can use the worksheet change event like this:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then ' did a value in column B change?
Cells(Target.Row, 1) = Now ' write date and time in column A
End If
End Sub
Related
It's possible make automatic move between columns and cell?
For Example:
I want only column A,B,C(Column A-item number Column B-LP(license plate) Column-C Location
I want scan barcode and cursor from column A2 go to right to Column B2 form column B to Column C2 but from column C2 I want back to Column A3 next Cell like automatic is possible ?
now I have like this but still I must use Ctrl+a then I back to Column A3.
If the scanner is set to press Enter, use this piece of code in Worksheet_Change event:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.count = 1 Then
If Target.Column = 1 Or Target.Column = 2 Then
Target.Offset(0, 1).Select
ElseIf Target.Column = 3 Then
Target.Offset(1, -2).Select
End If
End If
End Sub
It will not move the selection if you modify something outside the A:C columns.
Easy alternative is to format the columns A to C as table (list object). And change the option Cell Movement After Enter in Excel options to right instead of down. Entering data will then go from column C to A in the next line:
Image 1: The values are just typed in and confirmed with Enter. Because column C is the last one in the table now it starts over in the next line column A.
The cell movement direction can also be changed by code
Application.MoveAfterReturnDirection = xlToRight
so you can eg. change it if the workbook opens and change it back if it closes, so it doesn't affect all your workbooks.
Option Explicit
Dim MoveAfterReturnDirection_ORIGINAL As Long
Private Sub Workbook_Open()
MoveAfterReturnDirection_ORIGINAL = Application.MoveAfterReturnDirection
Application.MoveAfterReturnDirection = xlToRight
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.MoveAfterReturnDirection = MoveAfterReturnDirection_ORIGINAL
End Sub
I have a cell in Excel that gets updated on basis of RAND() function.
Each time I update the cell, I want to capture the previous values in a separate column. So that I can compute mean later on.
How to achieve this??
Copy below into Worksheet module and change "A1" cell:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range("A1")) Is Nothing) Then
i = i + 1
Worksheets("Sheet1").Cells(i, 2).Value = Worksheets("Sheet1").Cells(1, 1).Value
End If
End Sub
Whenever date is entered in column B, date before 3 business date should be automatically inserted in column C. I get it with =IF(B15, WORKDAY(B15, -3), " ") this formula but unable to get it automatically inserted for future rows without adding formula to blank cells. I need it without adding extra blank cells. Any suggestions would be appreciated
First format column C to some date format and then insert this event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim B As Range
Set B = Range("B:B")
If Intersect(B, Target) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
v = Target.Value
If Not IsDate(v) Then Exit Sub
Application.EnableEvents = False
Target.Offset(0, 1) = Application.WorksheetFunction.WorkDay(v, -3)
Application.EnableEvents = True
End Sub
There will be no formulas entered in column C.
EDIT#1:
An alternative is to enter in C15:
=IF(B15="","",WORKDAY(B15,-3))
and copy down. The C cells will appear empty until the B cell is filled.
show numbers starting from 1 based on a cell value using vba.
For example, if you type 4 in cell A1, then range D1,D2,D3,D4 should display 1,2,3,4 respectively. If type 5 in cell A2, then range D1,D2,D3,D4,D5 should display 1,2,3,4,5.
Could anyone please help?
The below macro uses a worksheet change event to detect changes to the cell A1,
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" And IsNumeric(Range("A1")) Then
Dim i As Long
Columns(4).ClearContents
For i = 1 To Cells(1, 1)
Cells(i, 4) = i
Next i
End If
End Sub
Suppose there are two Worksheet 1, Worksheet 2. Both the Worksheets are have a 'Number' Column which ties the records together
Workshhet 2 has 'Date' Column for each unique Number in the 'Number' column, Whenever Worksheet 2 'Date' column is changed i want to update a Column 'Times Changed' in Worksheet 1 for the unique Number in Worksheet 1 associated with the unique Number of Worksheet 2.
Please help me guys! :)
I have tried the following
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then [C5].Value = [C5].Value + 1
End Sub
Your code should work within the same sheet. If you want to count the number of times the cell is changed in an other sheet, say Sheet2, then you would have to change the code to something like:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Target, Range("A1:A100")) Is Nothing Then
ActiveWorkbook.Sheets("Sheet2").Cells(Target.Row, 3).Value = ActiveWorkbook.Sheets("Sheet2").Cells(Target.Row, 3).Value + 1
End If
End Sub
This change event only reacts on change to cells in A1:A100 and then changes the count in the corresponding cell in the C row on Sheet2.