Agnarr
New Member
- Joined
- Jan 15, 2023
- Messages
- 29
- Office Version
- 365
- Platform
- Windows
Hello Everyone!
A code that works perfectly brings from a sheet called "codes" the name and price of a product in my table, specifically in column d.
My problem is that I want to insert in column E the amount taken from each product and have the new price show in column E.
e.g.
one product has a price of 2$ but the cell in column E signifying the quantity is empty (that means 1), at which case I need the price to be shown in column C
another product has a price of 3$ but the cell in column E signifying the quantity has a value of 2, at which case I need the price of 3*2=6 to be shown in column C.
So in column C I have " =IF(E2="";D2;D2*E2) " but I need it integrated inside the vba code.
Please help?
A code that works perfectly brings from a sheet called "codes" the name and price of a product in my table, specifically in column d.
My problem is that I want to insert in column E the amount taken from each product and have the new price show in column E.
e.g.
one product has a price of 2$ but the cell in column E signifying the quantity is empty (that means 1), at which case I need the price to be shown in column C
another product has a price of 3$ but the cell in column E signifying the quantity has a value of 2, at which case I need the price of 3*2=6 to be shown in column C.
So in column C I have " =IF(E2="";D2;D2*E2) " but I need it integrated inside the vba code.
Please help?
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Intersect(Target, Sh.Range("g:g")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Dim fnd As Range
Set fnd = Sheets("codes").Range("A:A").Find(Target.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not fnd Is Nothing Then
Target.Offset(0, -5).Value = fnd.Offset(0, 1).Value
Target.Offset(0, -3).Value = fnd.Offset(0, 2).Value
End If
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim ws As Worksheet
Set ws = Sh
Call Workbook_SheetChange(ws, ws.Cells(1, 1)) ' Trigger the code for the new sheet
End Sub