[RESOLVED]Macro Modification
dear friend below macro work fine for me.only the thing is this macro final answer giving as a value.
ex- =250-50=200
this macro giving that final answer i mean 200.but i need answer like this =250-50
when i click that cell it should =250-50 like this.not only =200
pls any body can modify this macro.other whole thing in macro work very well.
Code:
Sub PackingToProductionUpdate()
Dim LotFind As Range, Lots As Range, LotNum As Range
Dim LotVal As Double
Application.ScreenUpdating = False
Set Lots = Sheets("Packing").Range("F5", Range("F" & Rows.Count).End(xlUp))
On Error Resume Next
For Each LotNum In Lots
With Sheets("Production")
Set LotFind = .Columns("K:K").Find(Left(LotNum, 6), After:=.Range("K" & Rows.Count), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not LotFind Is Nothing Then
LotVal = LotFind.Offset(0, -1).Value - LotNum.Offset(0, 1).Value
If LotVal <= 0 Then
LotFind.EntireRow.Delete xlShiftUp
Else
LotFind.Offset(0, -1).Value = LotVal
End If
LotNum.EntireRow.ClearContents
Set LotFind = Nothing
End If
End With
Next LotNum
Application.ScreenUpdating = True
End Sub
Re: [RESOLVED]Macro Modification
ohh. i have facing another problem here.if one time i'm reducing value above code work well.if i have reduce two time that answer is correct but i need like this,
ex-
one time we reduce values it's ok =200-50
if i reduce value again answer coming =150-50
it should =200-50-50
pls help me...
Re: [RESOLVED]Macro Modification
Your code contains some errors. This is better:
Code:
Sub packingupdate()
Dim LotFind As Range, Lots As Range, LotNum As Range
Dim LotVal As Double
Application.ScreenUpdating = False
With Sheets("Packing")
Set Lots = .Range("F5", .Range("F" & .Rows.Count).End(xlUp))
End With
With Sheets("Production")
For Each LotNum In Lots
If Trim(LotNum.Value) <> "" Then
Set LotFind = .Columns("K:K").Find(Left(LotNum, 6), After:=.Range("K" & Rows.Count), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not LotFind Is Nothing Then
LotVal = LotFind.Offset(0, -1).Value - LotNum.Offset(0, 1).Value
If LotVal <= 0 Then
LotFind.EntireRow.Delete xlShiftUp
ElseIf LotFind.Offset(0, -1).HasFormula Then
LotFind.Offset(0, -1).Formula = LotFind.Offset(0, -1).Formula & "-" & LotNum.Offset(0, 1).Value
Else
LotFind.Offset(0, -1).Formula = "=" & LotFind.Offset(0, -1).Value & "-" & LotNum.Offset(0, 1).Value
End If
LotNum.EntireRow.ClearContents
End If
End If
Next
End With
Application.ScreenUpdating = True
End Sub