VBA working most of the time... Please Help

Lazarus3D

New Member
Joined
Apr 2, 2012
Messages
5
Ok so here is the issue. I have a VBA that pulls the information from one sheet and puts it in another sheet on the same workbook. Everything thing works great except for whatever reason it is picky on what it pulls and what it does not.

On WorkSheet "Calculator" I have 4 Columns (A:D). Column A is "Code", Column B is "Item", Column C is "Qty". Column D is "Price". There are 20 possible codes that can be placed in Column A. I have a Cntrl Button that when click it takes all the information from Sheet "Calculator" and puts it in Sheet "Posted". Now that is the easy part. What the VBA is doing is looking on the Sheet "Posted" to see if any of the "Codes" from Sheet "Calculator" have already been copied. If it has then the "Qty" column just gets increased. This VBA works perfectly and I have found no issues with it. However, the issue I am running into is if one of the Codes has not been added yet, then it finds the next available row and adds the Code and its information to that row. This works great as well, however, the problem I am having is that if I were to type "Codes" 1-20 in Cells A6:A25 on Sheet "Calculater" and click the Post Transaction Button and the "Posted" sheet is completely blank then it will copy Codes 1,5-9,11-20 and skip 2,3,4 and 10. Now if I erase everything and redo those same steps the next time it will copy everything but code 10. It is extremely weird. I am new to VBA and I am positive there is a much better way of doing it but I am teaching myself and figuring it out as I go. Any help is greatly appreciated. I hope I have explained myself clearly but please let me know if any additional information is needed.

Code:
Sub PostSubmit()
 
Application.ScreenUpdating = False
    Dim FindA, FindB, FindC, FindD, FindE, FindF, FindG, FindH, FindI, FindJ, FindK, FindL, FindM, FindN, FindO, FindP, FindQ, FindR, FindS, FindT As String
    Dim FoundRangeA, FoundRangeB, FoundRangeC, FoundRangeD, FoundRangeE, FoundRangeF, FoundRangeG, FoundRangeH, FoundRangeI, FoundRangeJ, FoundRangeK, FoundRangeL, FoundRangeM, FoundRangeN, FoundRangeO, FoundRangeP, FoundRangeQ, FoundRangeR, FoundRangeS, FoundRangeT As Range
 
    FindA = Sheets("CALCULATOR").Range("A6")
    FindB = Sheets("CALCULATOR").Range("A7")
    FindC = Sheets("CALCULATOR").Range("A8")
    FindD = Sheets("CALCULATOR").Range("A9")
    FindE = Sheets("CALCULATOR").Range("A10")
    FindF = Sheets("CALCULATOR").Range("A11")
    FindG = Sheets("CALCULATOR").Range("A12")
    FindH = Sheets("CALCULATOR").Range("A13")
    FindI = Sheets("CALCULATOR").Range("A14")
    FindJ = Sheets("CALCULATOR").Range("A15")
    FindK = Sheets("CALCULATOR").Range("A16")
    FindL = Sheets("CALCULATOR").Range("A17")
    FindM = Sheets("CALCULATOR").Range("A18")
    FindN = Sheets("CALCULATOR").Range("A19")
    FindO = Sheets("CALCULATOR").Range("A20")
    FindP = Sheets("CALCULATOR").Range("A21")
    FindQ = Sheets("CALCULATOR").Range("A22")
    FindR = Sheets("CALCULATOR").Range("A23")
    FindS = Sheets("CALCULATOR").Range("A24")
    FindT = Sheets("CALCULATOR").Range("A25")
 
    Worksheets("POSTED").Activate
 
    Set FoundRangeA = Sheets("POSTED").Cells.Find(what:=FindA, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeB = Sheets("POSTED").Cells.Find(what:=FindB, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeC = Sheets("POSTED").Cells.Find(what:=FindC, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeD = Sheets("POSTED").Cells.Find(what:=FindD, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeE = Sheets("POSTED").Cells.Find(what:=FindE, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeF = Sheets("POSTED").Cells.Find(what:=FindF, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeG = Sheets("POSTED").Cells.Find(what:=FindG, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeH = Sheets("POSTED").Cells.Find(what:=FindH, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeI = Sheets("POSTED").Cells.Find(what:=FindI, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeJ = Sheets("POSTED").Cells.Find(what:=FindJ, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeK = Sheets("POSTED").Cells.Find(what:=FindK, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeL = Sheets("POSTED").Cells.Find(what:=FindL, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeM = Sheets("POSTED").Cells.Find(what:=FindM, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeN = Sheets("POSTED").Cells.Find(what:=FindN, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeO = Sheets("POSTED").Cells.Find(what:=FindO, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeP = Sheets("POSTED").Cells.Find(what:=FindP, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeQ = Sheets("POSTED").Cells.Find(what:=FindQ, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeR = Sheets("POSTED").Cells.Find(what:=FindR, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeS = Sheets("POSTED").Cells.Find(what:=FindS, LookIn:=xlFormulas, lookat:=xlWhole)
    Set FoundRangeT = Sheets("POSTED").Cells.Find(what:=FindT, LookIn:=xlFormulas, lookat:=xlWhole)
 
    If FindA = "" Then
    MsgBox "Nothing to Post"
    End
    End If
    If FindA > 0 And Sheets("POSTED").Range("A6") = "" Then
        Sheets("POSTED").Range("A6") = Sheets("CALCULATOR").Range("A6")
        Sheets("POSTED").Range("A6").Offset(0, 1) = Sheets("CALCULATOR").Range("A6").Offset(0, 1)
        Sheets("POSTED").Range("A6").Offset(0, 2) = Sheets("CALCULATOR").Range("A6").Offset(0, 2)
        Sheets("POSTED").Range("A6").Offset(0, 3) = Sheets("CALCULATOR").Range("A6").Offset(0, 3)
        End If
 
    If FindA > 0 And FoundRangeA Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A6")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A6").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A6").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A6").Offset(0, 3)
    Else
        FoundRangeA.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C6") + FoundRangeA.Offset(0, 6).Value
        End If
 
    If FindB = "" Then GoTo Two:
 
    If FindB > 0 And FoundRangeB Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A7")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A7").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A7").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A7").Offset(0, 3)
    Else
        FoundRangeB.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C7") + FoundRangeB.Offset(0, 6).Value
        End If
 
    If FindC = "" Then GoTo Two:
 
    If FindC > 0 And FoundRangeC Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A8")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A8").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A8").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A8").Offset(0, 3)
    Else
        FoundRangeC.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C8") + FoundRangeC.Offset(0, 6).Value
        End If
 
    If FindD = "" Then GoTo Two:
 
    If FindD > 0 And FoundRangeD Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A9")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A9").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A9").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A9").Offset(0, 3)
    Else
        FoundRangeD.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C9") + FoundRangeD.Offset(0, 6).Value
        End If
 
    If FindE = "" Then GoTo Two:
 
    If FindE > 0 And FoundRangeE Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A10")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A10").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A10").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A10").Offset(0, 3)
    Else
        FoundRangeE.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C10") + FoundRangeE.Offset(0, 6).Value
        End If
 
    If FindF = "" Then GoTo Two:
 
    If FindF > 0 And FoundRangeF Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A11")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A11").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A11").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A11").Offset(0, 3)
    Else
        FoundRangeF.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C11") + FoundRangeF.Offset(0, 6).Value
        End If
 
    If FindG = "" Then GoTo Two:
 
    If FindG > 0 And FoundRangeG Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A12")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A12").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A12").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A12").Offset(0, 3)
    Else
        FoundRangeG.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C12") + FoundRangeG.Offset(0, 6).Value
        End If
 
    If FindH = "" Then GoTo Two:
 
    If FindH > 0 And FoundRangeH Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A13")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A13").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A13").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A13").Offset(0, 3)
    Else
        FoundRangeH.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C13") + FoundRangeH.Offset(0, 6).Value
        End If
 
    If FindI = "" Then GoTo Two:
 
    If FindI > 0 And FoundRangeI Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A14")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A14").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A14").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A14").Offset(0, 3)
    Else
        FoundRangeI.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C14") + FoundRangeI.Offset(0, 6).Value
        End If
 
    If FindJ = "" Then GoTo Two:
 
    If FindJ > 0 And FoundRangeJ Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A15")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A15").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A15").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A15").Offset(0, 3)
    Else
        FoundRangeJ.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C15") + FoundRangeJ.Offset(0, 6).Value
        End If
 
    If FindK = "" Then GoTo Two:
 
    If FindK > 0 And FoundRangeK Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A16")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A16").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A16").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A16").Offset(0, 3)
    Else
        FoundRangeK.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C16") + FoundRangeK.Offset(0, 6).Value
        End If
 
    If FindL = "" Then GoTo Two:
 
    If FindL > 0 And FoundRangeL Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A17")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A17").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A17").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A17").Offset(0, 3)
    Else
        FoundRangeL.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C17") + FoundRangeL.Offset(0, 6).Value
        End If
 
    If FindM = "" Then GoTo Two:
 
    If FindM > 0 And FoundRangeM Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A18")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A18").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A18").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A18").Offset(0, 3)
    Else
        FoundRangeM.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C18") + FoundRangeM.Offset(0, 6).Value
        End If
 
    If FindN = "" Then GoTo Two:
 
    If FindN > 0 And FoundRangeN Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A19")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A19").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A19").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A19").Offset(0, 3)
    Else
        FoundRangeN.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C19") + FoundRangeN.Offset(0, 6).Value
        End If
 
    If FindO = "" Then GoTo Two:
 
    If FindO > 0 And FoundRangeO Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A20")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A20").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A20").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A20").Offset(0, 3)
    Else
        FoundRangeO.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C20") + FoundRangeO.Offset(0, 6).Value
        End If
 
    If FindP = "" Then GoTo Two:
 
    If FindP > 0 And FoundRangeP Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A21")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A21").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A21").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A21").Offset(0, 3)
    Else
        FoundRangeP.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C21") + FoundRangeP.Offset(0, 6).Value
        End If
 
    If FindQ = "" Then GoTo Two:
 
    If FindQ > 0 And FoundRangeQ Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A22")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A22").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A22").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A22").Offset(0, 3)
    Else
        FoundRangeQ.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C22") + FoundRangeQ.Offset(0, 6).Value
        End If
 
    If FindR = "" Then GoTo Two:
 
    If FindR > 0 And FoundRangeR Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A23")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A23").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A23").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A23").Offset(0, 3)
    Else
        FoundRangeR.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C23") + FoundRangeR.Offset(0, 6).Value
        End If
 
    If FindS = "" Then GoTo Two:
 
    If FindS > 0 And FoundRangeS Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A24")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A24").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A24").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A24").Offset(0, 3)
    Else
        FoundRangeS.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C24") + FoundRangeS.Offset(0, 6).Value
        End If
 
    If FindT = "" Then GoTo Two:
    If FindT > 0 And FoundRangeT Is Nothing Then
        Sheets("POSTED").Range("A5").End(xlDown).Offset(1, 0).FormulaR1C1 = Sheets("CALCULATOR").Range("A25")
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 1).FormulaR1C1 = Sheets("CALCULATOR").Range("A25").Offset(0, 1)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 2).FormulaR1C1 = Sheets("CALCULATOR").Range("A25").Offset(0, 2)
        Sheets("POSTED").Range("A5").End(xlDown).Offset(0, 3).FormulaR1C1 = Sheets("CALCULATOR").Range("A25").Offset(0, 3)
    Else
        FoundRangeT.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C25") + FoundRangeT.Offset(0, 6).Value
        End If
Two:
 
    MsgBox "Items Posted Successfully"
    Sheets("CALCULATOR").Range("A6:D25") = ""
    Sheets("CALCULATOR").Select
    Range("A6").Select
    Exit Sub
 
Application.ScreenUpdating = True
 
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi and Welcome to the Board,

I wasn't able to replicate the results you described exactly.
For my test, if POSTED was entirely blank, the value from CALCULATED!A6 was written to POSTED!A6, and the value from CALCULATED!A25 was written to POSTED!A7.
All the values from CALCULATED!A7:A24 appeared to be skipped.

The cause of this result is the use of this expression:
Rich (BB code):
Sheets("POSTED").Range("A5").End(xlDown)

That technique will find the last row of data in Column A only if A5 is not blank, and there are no other blank cells in the data range.
If A5 is blank and A6:A9 have values, that expression will incorrectly reference A6 as the last row of data in Column A.

A more reliable technique to find the last row of data in Column A is:
Code:
Sheets("POSTED").Cells(Rows.Count,"A").End(xlUp)

There is also a problem with this part...

Code:
If FindA > 0 And Sheets("POSTED").Range("A6") = "" Then
    Sheets("POSTED").Range("A6") = Sheets("CALCULATOR").Range("A6")
    '....
[COLOR="Red"]If FindA [/COLOR]> 0 And FoundRangeA Is Nothing Then
    '....

On the first pass through, both of those If tests will be True and the value in A6 will be written twice.
Using ElseIf would be one way to remedy that.

It's clear you've put a lot of work into this code and it's a good start for being new to VBA. :)

Just ask if you want some help incoporating looping into the code to reduce some of the repetition.
 
Last edited:
Upvote 0
Jerry,

Thank you very much for your assistance. I am still having trouble with this VBA. I do not know if there is a way on here to be able to send you the Excel document that I am working with to show you what weird stuff it is doing. I have tried the ElseIf as you advised and I am not really having any luck with it. Of course I could be using it incorrectly as well. Just so you know the information that is being pulled and placed on the "Posted" sheet is used for a report. That being said "A5" will always have something in it and "A6" should always be the first row it uses unless there is something already posted in A6. As crude as my VBA is it is working except for it skips certain numbers. The weird thing is it will skip the same numbers no matter where I place them in range ("A6:A25"). There are around 71 possible numbers or "codes" that can be used. These numbers are inputted in the "Calculator" sheet and the information that corresponds to that number is pulled from a sheet called "DATA". I am not sure where the problem is coming from at the moment. However, if Code 10 is used it will not post no matter where I put it in the line up A6:A25. It's like it doesn't recognize it but will pick up the rest. Any thoughts to how to fix the insanity at the moment? Again thank you for taking the time to look at this.
 
Upvote 0
I reviewed the file you sent and found the reason for the mysterious results you observed.

The primary cause is that the .Cells.Find statements are searching the entire "POSTED" worksheet instead of just Column A, for example...
Code:
Set FoundRangeA = Sheets("POSTED").Cells.Find(what:=FindA, _
    LookIn:=xlFormulas, lookat:=xlWhole)

The strange results were due to there being some stray data outside the normal view of your sheet.

FoundRangeJ was finding the Value "10" off of the screen's view, then this statement below would try to "update" the Qty field 2 cells to the right of that incorrect cell. This is why it appeared Code 10 was being skipped.

Code:
FoundRangeJ.Offset(0, 2).Value = Sheets("CALCULATOR").Range("C15")  _
    + FoundRangeJ.Offset(0, 6).Value

In addition to deleting the stray data and resizing your UsedRange, you'll want to revise your Find statements to just search Column A.

Even without that data outside your screen view, your current code could incorrectly "Find" the number 10 under Qty and consider that Cell a match for Code 10.

Here's a rework of part of the code that uses a For...Next Loop to reduce repetition and make the code easier to maintain.
Code:
Sub PostSubmit2()
    Dim sItem As String, lRow As Long
    Dim wsCalc As Worksheet
    Set wsCalc = Sheets("CALCULATOR")
    
    On Error GoTo CleanUp
    Application.ScreenUpdating = False
    Application.EnableEvents = False
     
    With Sheets("POSTED")
        For lRow = 6 To 25
            sItem = wsCalc.Cells(lRow, "A")
            If sItem = vbNullString Then Exit For
[COLOR="Teal"]            '---Check if ItemCode is already Posted[/COLOR]
            Set rFound = .Columns("A").Find(What:=sItem, _
                LookIn:=xlFormulas, LookAt:=xlWhole)
            If rFound Is Nothing Then
[COLOR="teal"]                '---Add item to list[/COLOR]
                With .Cells(Rows.Count, "A").End(xlUp)
                    .Offset(1) = sItem
                    .Offset(1, 1) = wsCalc.Cells(lRow, "B")
                    .Offset(1, 2) = wsCalc.Cells(lRow, "C")
                    .Offset(1, 3) = wsCalc.Cells(lRow, "D")
                End With
            Else  [COLOR="teal"] '---Increase QTY[/COLOR]
                rFound.Offset(0, 2) = rFound.Offset(0, 2) _
                    + wsCalc.Cells(lRow, "C")
            End If
        Next
    End With
CleanUp:
    Application.ScreenUpdating = True
    Application.EnableEvents = True
End Sub

One last suggestion is to revisit your use of Worksheet_Change Event code.

You'll want to be very careful that this code isn't being triggered unexpectedly.

I'd suggest that you eliminate those parts for now and bring them back sparingly.
 
Last edited:
Upvote 0
It's funny now that you said that it is so easy to see that it is searching the whole document instead of just column "A". I have looked at that a thousand times and just didn't see it. I fixed that and it is pulling it all like it is supposed to! Thank you very much! I am looking over the additional code you supplied and I am trying to put it in as I can tell it is much simpler and contained then what I was trying to do. The only thing that confuses me is how it is actually posting it to the "Posted" sheet. I placed your code in and if there is information already there it is updating the QTY perfectly but if the code isn't already there it is not adding it to the posted sheet. I feel I am doing something wrong here but I just got home from a very long day of work so I may just be overlooking something. Either way I have it working which is great! I do like your approach much better and if you can help me with what mistake I am making that would be great. Either way you have made my day!

Thanks again!
 
Upvote 0
I'm happy to hear that helped. :)

The only thing that confuses me is how it is actually posting it to the "Posted" sheet.

It's referencing the Posted Sheet through the With Blocks....
Code:
With Sheets("POSTED")
    With .Cells(Rows.Count, "A").End(xlUp)
        .Offset(1) = sItem
        .Offset(1, 1) = wsCalc.Cells(lRow, "B")
        .Offset(1, 2) = wsCalc.Cells(lRow, "C")
        .Offset(1, 3) = wsCalc.Cells(lRow, "D")
    End With
End With

...which is equivalent to this....
Code:
Sheets("POSTED").Cells(Rows.Count, "A").End(xlUp).Offset(1) = sItem
Sheets("POSTED").Cells(Rows.Count, "A").Offset(1, 1) = wsCalc.Cells(lRow, "B")
Sheets("POSTED").Cells(Rows.Count, "A").Offset(1, 2) = wsCalc.Cells(lRow, "C")
Sheets("POSTED").Cells(Rows.Count, "A").Offset(1, 3) = wsCalc.Cells(lRow, "D")

I placed your code in and if there is information already there it is updating the QTY perfectly but if the code isn't already there it is not adding it to the posted sheet.

It's working for me. Make sure to delete all the stray data.
There was some data on the last couple rows of the worksheet and the values in Column A could be drawing your new Codes.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,336
Messages
6,124,330
Members
449,155
Latest member
ravioli44

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