Results 1 to 16 of 16

Thread: [RESOLVED]Macro Modification

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    Post [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
    Last edited by johncena; Mar 22nd, 2010 at 06:44 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Macro Modification

    i understand what you want but am unsure where it applies, the only place i can see is
    LotFind.Offset(0, -1).Value = LotVal
    try
    vb Code:
    1. LotFind.Offset(0, -1).Value = "'=" & LotFind.Offset(0, -1).Value & " - " & LotNum.Offset(0, 1).Value
    alternatively you could format the cells as text
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    Thumbs up Re: Macro Modification

    Quote Originally Posted by westconn1 View Post
    i understand what you want but am unsure where it applies, the only place i can see is


    try
    vb Code:
    1. LotFind.Offset(0, -1).Value = "'=" & LotFind.Offset(0, -1).Value & " - " & LotNum.Offset(0, 1).Value
    alternatively you could format the cells as text
    thanks a lot friend.it's work very well.REP+ add.thanks a lot again.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    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...

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Macro Modification

    LotFind.Offset(0, -1).Formula = "=" & LotFind.Offset(0, -1).Value & "-" & LotNum.Offset(0, 1).Value
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    Re: Macro Modification

    Quote Originally Posted by anhn View Post
    LotFind.Offset(0, -1).Formula = "=" & LotFind.Offset(0, -1).Value & "-" & LotNum.Offset(0, 1).Value
    dear anhn your code & westconn1's code both are same.my problem is not solved.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Macro Modification

    i don't understand where it can reduce or how many times

    also anhn's code is substantially different, to what i posted previously
    Last edited by westconn1; Mar 22nd, 2010 at 05:59 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Macro Modification

    dear anhn your code & westconn1's code both are same.my problem is not solved.
    They are not the same.

    pete's code gives value as a string
    "=200-50"

    My code produces a formula
    =200-50
    this formula gives a value of 150 in next round for the next formula:
    =150-50
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    Re: Macro Modification

    dear westconn1 & anhn pls don't get angry with me.my English is too bad.I'll try explain my requirement.anhn your understanding is correct.if i run this macro twice answer should =200-50-50.not =150-50.pls help me.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Macro Modification

    try changing to
    LotFind.Offset(0, -1).Value = "'=" & LotFind.Offset(0, -1).Text & " - " & LotNum.Offset(0, 1).Text

    without seeing the contents of the cells it is a bit hard to guess
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    Re: Macro Modification

    Quote Originally Posted by westconn1 View Post
    try changing to
    LotFind.Offset(0, -1).Value = "'=" & LotFind.Offset(0, -1).Text & " - " & LotNum.Offset(0, 1).Text

    without seeing the contents of the cells it is a bit hard to guess
    sorry sir.same answer.

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Macro Modification

    what is the content of lotfind.offset(0, -1) when the code runs?
    if it already contains the 150 value i do not see how you can translate that back, where is the cell containing =200 - 50 in relation to lotfind?

    maybe post a sample workbook, with some data and the code
    zip to attach to post
    if you are using 2007 saveAs earlier version, as not all have 2007
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    Re: Macro Modification

    Quote Originally Posted by westconn1 View Post
    what is the content of lotfind.offset(0, -1) when the code runs?
    if it already contains the 150 value i do not see how you can translate that back, where is the cell containing =200 - 50 in relation to lotfind?

    maybe post a sample workbook, with some data and the code
    zip to attach to post
    if you are using 2007 saveAs earlier version, as not all have 2007
    here i have attached sample work sheet.pls check it..
    Attached Files Attached Files

  14. #14
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Macro Modification

    dear westconn1 & anhn pls don't get angry with me.my English is too bad.I'll try explain my requirement.anhn your understanding is correct.if i run this macro twice answer should =200-50-50.not =150-50.pls help me.
    You said "me.my English is too bad.I'll" but your writing style is worst.
    In most Latin languages, after a full stop (.) or a comma (,) you should type a space to make your writing easier to read. The above should be:
    dear westconn1 & anhn pls don't get angry with me. My English is too bad. I'll try explain my requirement. anhn your understanding is correct. If i run this macro twice answer should =200-50-50. Not =150-50. Pls help me.
    Try this:
    Code:
        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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    42

    Re: Macro Modification

    Quote Originally Posted by anhn View Post
    You said "me.my English is too bad.I'll" but your writing style is worst.
    In most Latin languages, after a full stop (.) or a comma (,) you should type a space to make your writing easier to read. The above should be:


    Try this:
    Code:
        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
    i really appreciate your advice sir. this macro code also work great. thanks a lot again. REP+.

  16. #16
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width