Advertisement

06.30.2008 at 11:32PM PDT, ID: 23529246
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Amend VBA Code

Asked by keilah in Microsoft Excel Spreadsheet Software

Tags: , ,

Hi Expets

Need to amend the following vba code  so that the snippet section is added to the vba code below. Keep on getting a compile if error everytime i try, not sure what i am doing wrong in my step.


Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim Sheet As New Collection
Dim rng As Range
Dim rngRow As Long
Dim confirm As Boolean
Dim firstSupplierRow As Range
Dim lastSupplierRow As Range
Dim aSupplier As Range
Dim foundDemand As Boolean

If Not ThisWorkbook.Worksheets("Deal Selection").Range("I:I").Find(TextBox1.Value) Is Nothing Then
    MsgBox "CUSTOMER: " & TextBox1.Value & " Already Pre-Exists!", vbCritical, "Customer Duplication Error"
    Exit Sub
End If

    confirm = MsgBox("ARE YOU SURE YOU WANT TO ADD NEW CUSTOMER :> " & TextBox1.Value, vbYesNo, "ADDING CUSTOMER") = vbYes

    If confirm Then
        'Populate affected worksheets
        Sheet.Add ThisWorkbook.Worksheets("Deal Selection")
        Sheet.Add ThisWorkbook.Worksheets("Tables")
        Sheet.Add ThisWorkbook.Worksheets("Alloc (sc.1)")
        Sheet.Add ThisWorkbook.Worksheets("Alloc (sc.2)")
        Sheet.Add ThisWorkbook.Worksheets("Alloc (sc.3)")
        Sheet.Add ThisWorkbook.Worksheets("Modelling (Vol)")
        Sheet.Add ThisWorkbook.Worksheets("Allocation (Vol)")
        Sheet.Add ThisWorkbook.Worksheets("Cashflow Yearly")
        Sheet.Add ThisWorkbook.Worksheets("Cashflow Q4")
        Sheet.Add ThisWorkbook.Worksheets("Pricing Supply")
        Sheet.Add ThisWorkbook.Worksheets("Pricing Demand")
        Sheet.Add ThisWorkbook.Worksheets("CashFlow")
        Sheet.Add ThisWorkbook.Worksheets("Revenue")
        Sheet.Add ThisWorkbook.Worksheets("Cost of Purchase")
        Sheet.Add ThisWorkbook.Worksheets("Shipping BOG")
        Sheet.Add ThisWorkbook.Worksheets("Shipping UFC")
       
        For Each ws In Sheet
            If ws.Name = "Deal Selection" Then
                Set rng = ws.Range("I:I").Find(TextBox1.Value)
                If rng Is Nothing Then
'                    Debug.Print "add new item " & TextBox1.Value
                    ws.Range("I" & ws.Rows.Count).End(xlUp).Offset(1, 0).Value = TextBox1.Value
                End If
            ElseIf ws.Name = "Tables" Then
                Set rng = ws.Range("L:L").Find(TextBox1.Value)
                If rng Is Nothing Then
'                    Debug.Print "add new item " & TextBox1.Value
                    ws.Range("L" & ws.Rows.Count).End(xlUp).Offset(1, 0).Value = TextBox1.Value
                    ws.Range("L" & ws.Rows.Count).End(xlUp).HorizontalAlignment = xlCenter
                    ws.Range("L" & ws.Rows.Count).End(xlUp).Font.Color = 12632256
                    ws.Range("L" & ws.Rows.Count).End(xlUp).Borders(xlLeft).LineStyle = xlContinuous
                    ws.Range("L" & ws.Rows.Count).End(xlUp).Borders(xlRight).LineStyle = xlContinuous
                    ws.Range("L" & ws.Rows.Count).End(xlUp).Borders(xlBottom).LineStyle = xlContinuous
                End If
            ElseIf ws.Name = "CashFlow Q4" Or ws.Name = "CashFlow Yearly" Then
                Set lastSupplierRow = ws.Range("B:B").Find("Supply").Offset(1, 0)
                Do While lastSupplierRow.Row < ws.Range("C" & ws.Rows.Count).End(xlUp).Row
                    Set firstSupplierRow = lastSupplierRow
                    Do While lastSupplierRow.Value = firstSupplierRow.Value
                        Set lastSupplierRow = lastSupplierRow.Offset(1, 0)
                    Loop
                    foundDemand = False
                    For rngRow = firstSupplierRow.Row To lastSupplierRow.Offset(-1, 0).Row
                        'Debug.Print ws.Range("B" & rngRow).Value & " : " & ws.Range("B" & rngRow).Offset(0, 1).Value
                        If LCase(ws.Range("B" & rngRow).Offset(0, 1).Value) = LCase(TextBox1.Value) Then foundDemand = True
                    Next
                    If Not foundDemand Then
                        lastSupplierRow.Offset(-1, 0).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
'                       lastSupplierRow.EntireRow.Borders(xlEdgeTop).LineStyle = xlNone
                        lastSupplierRow.Offset(-2, 0) = firstSupplierRow.Value
                        lastSupplierRow.Offset(-2, 1) = TextBox1.Value
                        lastSupplierRow.Offset(-2, 2) = "MMUS$"
                        lastSupplierRow.Offset(-2, 3) = "CF_" & firstSupplierRow.Value & "_" & TextBox1.Value
                    sup = lastSupplierRow.Offset(-2, 0)
                    sup = Replace(sup, "+", "_plus")
                    sup = Replace(sup, ", ", "~")
                    sup = Replace(sup, " ", "_")
                    sup = Replace(sup, "~", ", ")
                    sup = Replace(sup, "-", "_")
                    sup = Replace(sup, "/", "_")
                    sup = Replace(sup, "(", "")
                    sup = Replace(sup, ")", "")
                    dem = lastSupplierRow.Offset(-2, 1)
                    dem = Replace(dem, "+", "_plus")
                    dem = Replace(dem, ", ", "~")
                    dem = Replace(dem, " ", "_")
                    dem = Replace(dem, "~", ", ")
                    dem = Replace(dem, "-", "_")
                    dem = Replace(dem, "/", "_")
                    dem = Replace(dem, "(", "")
                    dem = Replace(dem, ")", "")
                    lastSupplierRow.Offset(-2, 4).Resize(1, 128).FormulaArray = _
                    "=if(or(" & _
                    "iserror((Revenue_" & dem & "_" & sup & _
                        " - " & "Purchase_" & sup & "_" & dem & "))" & _
                    ", A" & startrow + 1 & " = FALSE" & _
                    ")" & _
                ",0" & _
                "," & _
                    "(Revenue_" & dem & "_" & sup & _
                    " - " & "Purchase_" & sup & "_" & dem & "))"
                    End If
                    Set lastSupplierRow = lastSupplierRow.Offset(1, 0)
                Loop
                lastSupplierRow.Offset(0, 1).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(0, 2).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(0, 3).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(0, 4).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(0, 0).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(0, 0).Borders(xlLeft).Weight = xlMedium
                lastSupplierRow.Offset(0, 131).Borders(xlRight).LineStyle = xlContinuous
                lastSupplierRow.Offset(0, 131).Borders(xlRight).Weight = xlMedium
                lastSupplierRow.Resize(1, 132).Borders(xlEdgeTop).LineStyle = xlContinuous
                lastSupplierRow.Resize(1, 132).Borders(xlEdgeTop).Weight = xlMedium
                'Next supplier
            Else
               Set lastSupplierRow = ws.Range("B:B").Find("Supply", LookAt:=xlWhole).Offset(1, 0)
                Do While lastSupplierRow.Row < ws.Range("C" & ws.Rows.Count).End(xlUp).Row
                    Set firstSupplierRow = lastSupplierRow
                    Do While lastSupplierRow.Value = firstSupplierRow.Value
                        Set lastSupplierRow = lastSupplierRow.Offset(1, 0)
                    Loop
                    foundDemand = False
                    For rngRow = firstSupplierRow.Row To lastSupplierRow.Offset(-1, 0).Row
                        'Debug.Print ws.Range("B" & rngRow).Value & " : " & ws.Range("B" & rngRow).Offset(0, 1).Value
                        If LCase(ws.Range("B" & rngRow).Offset(0, 1).Value) = LCase(TextBox1.Value) Then foundDemand = True
                    Next
                    If Not foundDemand Then
                        lastSupplierRow.EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                        lastSupplierRow.Offset(-1, 0).EntireRow.Borders(xlEdgeTop).LineStyle = xlNone
                        lastSupplierRow.Offset(-1, 0) = firstSupplierRow.Value
                        lastSupplierRow.Offset(-1, 1) = TextBox1.Value
                        lastSupplierRow.Offset(-1, 2) = "Tbtu"
                    sup = lastSupplierRow.Offset(-1, 0)
                    sup = Replace(sup, "+", "_plus")
                    sup = Replace(sup, ", ", "~")
                    sup = Replace(sup, " ", "_")
                    sup = Replace(sup, "~", ", ")
                    sup = Replace(sup, "-", "_")
                    sup = Replace(sup, "/", "_")
                    sup = Replace(sup, "(", "")
                    sup = Replace(sup, ")", "")
                    dem = lastSupplierRow.Offset(-1, 1)
                    dem = Replace(dem, "+", "_plus")
                    dem = Replace(dem, ", ", "~")
                    dem = Replace(dem, " ", "_")
                    dem = Replace(dem, "~", ", ")
                    dem = Replace(dem, "-", "_")
                    dem = Replace(dem, "/", "_")
                    dem = Replace(dem, "(", "")
                    dem = Replace(dem, ")", "")
                        lastSupplierRow.Offset(-1, 3) = "Vol_" & sup & "_" & dem
'                        lastSupplierRow.Offset(-2, 4).Resize(1, 128).FormulaArray = "=Vol_" & sup & "_" & dem
                    End If
                Loop
                lastSupplierRow.Offset(-1, 1).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 2).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 3).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 4).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 0).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 0).Borders(xlLeft).Weight = xlMedium
                lastSupplierRow.Offset(-1, 131).Borders(xlRight).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 131).Borders(xlRight).Weight = xlMedium
                lastSupplierRow.Resize(1, 132).Borders(xlEdgeTop).LineStyle = xlContinuous
                lastSupplierRow.Resize(1, 132).Borders(xlEdgeTop).Weight = xlMedium
                'Next supplier
             End If
           
        Next
        reformat_Sheets
Else

MsgBox TextBox1.Value & " - CUSTOMER NOT ADDED", , "USER CANCEL"

End If
    Unload Me

End SubStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
ElseIf ws.Name = "Pricing Supply" Or ws.Name = "Pricing Demand" Then
                Set lastSupplierRow = ws.Range("B:B").Find("Supply", LookAt:=xlWhole).Offset(1, 0)
                Do While lastSupplierRow.Row < ws.Range("C" & ws.Rows.Count).End(xlUp).Row
                    Set firstSupplierRow = lastSupplierRow
                    Do While lastSupplierRow.Value = firstSupplierRow.Value
                        Set lastSupplierRow = lastSupplierRow.Offset(1, 0)
                    Loop
                    foundDemand = False
                    For rngRow = firstSupplierRow.Row To lastSupplierRow.Offset(-1, 0).Row
                        'Debug.Print ws.Range("B" & rngRow).Value & " : " & ws.Range("B" & rngRow).Offset(0, 1).Value
                        If LCase(ws.Range("B" & rngRow).Offset(0, 1).Value) = LCase(TextBox1.Value) Then foundDemand = True
                    Next
                    If Not foundDemand Then
                        lastSupplierRow.EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                        lastSupplierRow.Offset(-1, 0).EntireRow.Borders(xlEdgeTop).LineStyle = xlNone
                        lastSupplierRow.Offset(-1, 0) = firstSupplierRow.Value
                        lastSupplierRow.Offset(-1, 1) = TextBox1.Value
                        lastSupplierRow.Offset(-1, 2) = "$/mmBTU"
                    sup = lastSupplierRow.Offset(-1, 0)
                    sup = Replace(sup, "+", "_plus")
                    sup = Replace(sup, ", ", "~")
                    sup = Replace(sup, " ", "_")
                    sup = Replace(sup, "~", ", ")
                    sup = Replace(sup, "-", "_")
                    sup = Replace(sup, "/", "_")
                    sup = Replace(sup, "(", "")
                    sup = Replace(sup, ")", "")
                    dem = lastSupplierRow.Offset(-1, 1)
                    dem = Replace(dem, "+", "_plus")
                    dem = Replace(dem, ", ", "~")
                    dem = Replace(dem, " ", "_")
                    dem = Replace(dem, "~", ", ")
                    dem = Replace(dem, "-", "_")
                    dem = Replace(dem, "/", "_")
                    dem = Replace(dem, "(", "")
                    dem = Replace(dem, ")", "")
                        lastSupplierRow.Offset(-1, 3) = "Price_" & sup & "_" & dem
'                        lastSupplierRow.Offset(-2, 4).Resize(1, 128).FormulaArray = "=Vol_" & sup & "_" & dem
                    End If
                Loop
                lastSupplierRow.Offset(-1, 1).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 2).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 3).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 4).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 0).Borders(xlLeft).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 0).Borders(xlLeft).Weight = xlMedium
                lastSupplierRow.Offset(-1, 131).Borders(xlRight).LineStyle = xlContinuous
                lastSupplierRow.Offset(-1, 131).Borders(xlRight).Weight = xlMedium
                lastSupplierRow.Resize(1, 132).Borders(xlEdgeTop).LineStyle = xlContinuous
                lastSupplierRow.Resize(1, 132).Borders(xlEdgeTop).Weight = xlMedium
                'Next supplier
 
Loading Advertisement...
 
[+][-]07.01.2008 at 12:35AM PDT, ID: 21905559

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 12:48AM PDT, ID: 21905605

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 12:58AM PDT, ID: 21905647

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 01:28AM PDT, ID: 21905776

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 01:30AM PDT, ID: 21905782

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 01:36AM PDT, ID: 21905807

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 01:42AM PDT, ID: 21905831

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 01:46AM PDT, ID: 21905852

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 01:53AM PDT, ID: 21905881

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 02:01AM PDT, ID: 21905922

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 02:02AM PDT, ID: 21905928

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 02:02AM PDT, ID: 21905930

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: Microsoft, Excel, 2003
Sign Up Now!
Solution Provided By: chris_bottomley
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.01.2008 at 02:27AM PDT, ID: 21906026

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 02:33AM PDT, ID: 21906051

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.01.2008 at 03:06AM PDT, ID: 21906176

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628