How do I combine the following Private Sub Worksheet Changes?

corey510

New Member
Joined
Oct 18, 2017
Messages
7
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("E:F")) Is Nothing Then Exit Sub

Application.EnableEvents = False 'Prevent infinite looping

If Target.Column = 5 Then
'User has changed something in column A:
Target.Offset(0, 1).Value = Round(Target / Range("H1").Value, 5)
Else
'User has changed something in column B:
Target.Offset(0, -1).Value = Round(Target * Range("H1").Value, 5)
End If

Application.EnableEvents = True

End Sub




and




Private Sub Worksheet_change(ByVal Target As Range)
Dim A As Range, B As Range, Inte As Range, RR As Range
Set A = Range("A3:A1002")
Set Inte = Intersect(A, Target)
If Inte Is Nothing Then Exit Sub
Application.EnableEvents = False
For Each RR In Inte
If RR.Value > 0 Then
RR.Offset(0, 1).Value = Date
Else
RR.Offset(0, 1).Value = ""
End If
Next RR
Application.EnableEvents = True
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim rng As Range, rr As Range
Set rng = Union(Range("A:A"), Range("E:F"))
Application.EnableEvents = False
    If Not Intersect(rng, Target) Is Nothing Then
        If Target.Column = 5 Then
            Target.Offset(0, -1).Value = Round(Target / Range("H1").Value, 5)
        ElseIf Target.Column = 6 Then
            Target.Offset(0, -1).Value = Round(Target * Range("h1").Value, 5)
        End If
        If Not Intersect(Range("A:A"), Target) Is Nothing Then
            For Each rr In Range("A3", Cells(Rows.Count, 1).End(xlUp))
                If rr.Value > 0 Then
                    rr.Offset(, 1).Value = Date
                Else
                    rr.Offset(, 1).Value = ""
                End If
            Next
        End If
    End If
Application.EnableEvents = True
End Sub
 
Upvote 0
Thank you for the code. Regarding populating the date in column "B" when a value was entered in Colum"A", my old code would remove the date in column "B" when I deleted values in Colum "A" ( row by row). That feature is not working now. I also noticed I cannot get the code to run when copying and pasting values in the appropriate cells. Here is my old code which worked well:
1585146649299.png


I was then trying to create an active currency conversion calculator in my sheet. Currenty the user must enter a cost manually in columns "E" or "F". If USD teh user would enter the value in Column"E" . the value will be then be duplicated in column "V" so that other cells in that row of the sheet will calculate accordingly. If a user entered a value in column "F" ( Euros), the value would be duplicated in column "U" and would then be converted to USD in column "V" using the conversion rate in cell $U$1.

I wanted to eliminate the redundant cells. When the user enters a value in USD in a cell in column"E", the adjacent cell in Column"F" will automatically populate the currency conversion to EUROs and vise versa. If I enter or change the value in a cell in column "F" it will adjust or generate the appropriate conversion back to USD in the adjacent cell in Column "E". I should be able to enter a value or paste a value in either cell. If the value is cleared in either cell, the adjacent cell should also clear.


1585145782128.png


My sheet looks like this.
 

Attachments

  • 1585144827828.png
    1585144827828.png
    11.9 KB · Views: 0
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,688
Members
448,978
Latest member
rrauni

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