Copy Value from Formula and paste on the next column/cell automatically

Rubleon

New Member
Joined
Dec 19, 2019
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello team, can you please help me?

Thanks in advance.

I'm trying to imagine how to have a column that copy/paste the value from the previous cell, who gets the data through a formula. this through a VBA code.

So this is the formula used to populate column "B", which extracts the date from the "Entry Date" sheet.
=INDEX('Entry Date'!$A$2:$G$3,MATCH(B$1,'Entry Date'!$A$2:$A$3,0),MATCH($A2,'Entry Date'!$A$2:$G$2,0))
and what I want is to populate column "C" with the date value, each time I populate the next empty cell in column "B". this to properly use the date filter and be able to use that column for an "=IF AND AND" formula.

and I want this to happen, as it occurs on column F, every time I populate or change the status in column E.
attached you will find the example performed from the complete data.
1577734082079.png



Invoice No.Shipment DatePaste Date As ValueColumnStatusLast Update
Data 109/11/2019Must Reject30/12/2019
Data 208/11/2019Passed30/12/2019
Data 301/11/2019
Data 401/11/2019Passed30/12/2019
Data 501/11/2019
Data 605/11/2019
Data 7

and this is the VBA code used to auto-populate the column F

Private Sub Worksheet_Change(ByVal Target As Range)
'Update DATES
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("E:E"), Target)
xOffsetColumn = 1
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd/mm/yyyy"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Kind of hard to determine for sure what you want, but this will put the value of column B into column C and put the current date into column F for any cell with a value in column E.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.EnableEvents = False
Dim c As Range
    If Not Intersect(Target, Range("E:E")) Is Nothing Then
        Range("C2", Cells(Rows.Count, 2).End(xlUp).Offset(, 1)) = _
        Range("B2", Cells(Rows.Count, 2).End(xlUp)).Value
        For Each c In Range("E2", Cells(Rows.Count, 5).End(xlUp))
            If c <> "" Then
                c.Offset(, 1) = Date
            Else
                c.Offset(, 1) = ""
            End If
        Next
    End If
    Columns("C").NumberFormat = "dd/mm/yyyy"
Application.EnableEvents = True
End Sub
 
Upvote 0
Thanks JLGWhiz,

apologies if i didn't described it as i should.

I get the values of the "Shipment Value", with an index match formula from another file... and somehow i cannot use that "Date Value", as described with the below example.

1578265091157.png
(tried to do it through the XL2BB range to BBCode, but didnt work)...
this formula goes into cell Q2
=IF(AND(M2<=P2,N2>=P2),O2)


I need help to create a VBA code, who will automatically copy/paste the Date value from the "Shipment Date" column, in the next cell each time I populate the value on the "shipment Value" cell.
 
Upvote 0
Well, I thought that was part of what the code I wrote was doing. The problem is that the worksheet change will not work based on a change in column B because it is a calculation that causes the change and Excel ignores calculations as changes, so it does not trigger the Change Event. Conversely, if you use the Worksheet_Calculate to trigger the code, then it runs everytime a calculation occurs, whether it is in column B or not, so you would need to write the code to copy every item in column B to column C every time. Give this a try.

Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Range("B2", Cells(Rows.Count, 2).End(xlUp)).Copy
Range("C2").PasteSpecial xlPasteValues
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top