Consulting

Results 1 to 6 of 6

Thread: NEED CORRECTION IN MACRO

  1. #1

    NEED CORRECTION IN MACRO

    Hi everyone,I was using a macro in a workbook,it was working fine but now it works for the 1st row & copies it down to last row when i enter save option it works.Can someone please correct it & make it in a good shape so that i can use it at any other place.

    Sub sinoformula()
    '
    ' sinoformula Macro
    Dim Lr As Long
    Lr = ThisWorkbook.Sheets("INVOICE").Cells(Rows.Count, 6).End(xlUp).Row
    '
        Range("E8").Select
        Selection.FormulaArray = _
            "=IFERROR(INDEX(Table1[ID],MATCH(RC[2]&RC[3],INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        Selection.AutoFill Destination:=Range("E8:E" & Lr), Type:=xlFillDefault
        Range("E8:E" & Lr).Select
        Range("J8").Select
        Selection.FormulaArray = _
            "=IFERROR(INDEX(Table1[s.RATE],MATCH(RC[-3]&RC[-2],INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        Selection.AutoFill Destination:=Range("J8:J" & Lr), Type:=xlFillDefault
        Range("J8:J" & Lr).Select
        Range("K8").Select
        ActiveCell.FormulaR1C1 = "=IFERROR(RC[-2]*RC[-1],"""")"
        Range("K8").Select
        Selection.AutoFill Destination:=Range("K8:K" & Lr), Type:=xlFillDefault
        Range("K8:K" & Lr).Select
        Range("L8").Select
        Selection.FormulaArray = _
            "=IFERROR(INDEX(Table1[s.s.disc],MATCH(RC[-5]&RC[-4],INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        Selection.AutoFill Destination:=Range("L8:L" & Lr), Type:=xlFillDefault
        Range("L8:L" & Lr).Select
        Range("M8").Select
        ActiveCell.FormulaR1C1 = "=IFERROR(RC[-2]-RC[-2]*RC[-1]%,"""")"
        Range("M8").Select
        Selection.AutoFill Destination:=Range("M8:M" & Lr), Type:=xlFillDefault
        Range("M8:M" & Lr).Select
        Range("O8").Select
        Selection.FormulaArray = _
            "=IFERROR(INDEX(Table1[p.rate],MATCH(RC[-8]&RC[-7],INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        Selection.AutoFill Destination:=Range("O8:O" & Lr), Type:=xlFillDefault
        Range("O8:O" & Lr).Select
        Range("P8").Select
        ActiveCell.FormulaR1C1 = "=IFERROR(RC[-7]*RC[-1],"""")"
        Range("P8").Select
        Selection.AutoFill Destination:=Range("P8:P" & Lr), Type:=xlFillDefault
        Range("P8:P" & Lr).Select
        Range("Q8").Select
        Selection.FormulaArray = _
            "=IFERROR(INDEX(Table1[s.p.disc],MATCH(RC[-10]&RC[-9],INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        Selection.AutoFill Destination:=Range("Q8:Q" & Lr), Type:=xlFillDefault
        Range("Q8:Q" & Lr).Select
        Range("R8").Select
        ActiveCell.FormulaR1C1 = "=IFERROR(RC[-2]-RC[-2]*RC[-1]%,"""")"
        Range("R8").Select
        Selection.AutoFill Destination:=Range("R8:R" & Lr), Type:=xlFillDefault
        Range("R8:R" & Lr).Select
    End Sub

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    pls dont pm for requesting help. being online doest mean im available.
    members here are happy to help anyone if they can. so no pm's are required.

    that said, i see you slightly modified a recorded macro.

    a sample workbook might help us help you.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    here is a better way to insert formulas into cells.
    adopt them to your requirements.

    Range("E8:E" & LR).Formula = "Formula here"
    Range("J8:J" & LR).Formula = "Another Formula here"
    Range("K8:K" & LR).Formula = "3rd Formula here"
    '...
    '...
    '...
    Formula, FormulaArray or FormulaR1C1
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    I am attaching a file, problem started for me is from module4 named "customer",& it is still not working from there it made everything worse,now my starting formula is not working too,Another thing is that can i enter a formula in a module just like i entered in macro.
    Attached Files Attached Files

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are referring to another thread of yours which has been marked as solved 3 months ago.

    i really dont understand why you complain about the solution i posted there as it's not working or causing problems in this thread and after 3 months.

    even though i have lost the desire to provide a solution to this thread, i will post a macro which inserts formulas into cells. you should adopt it yourself to your needs.

    nothing more.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Sub Macro1()
    Dim LR As Long
    With Worksheets("INVOICE")
        LR = .Cells(.Rows.Count, 6).End(xlUp).Row
        .Range("E8:E" & LR).Formula = "=IFERROR(INDEX(Table1[ID],MATCH(G8&H8,INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        .Range("J8:J" & LR).Formula = "=IFERROR(INDEX(Table1[s.RATE],MATCH(G8&H8,INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        .Range("K8:K" & LR).Formula = "=IFERROR(I8*J8,"""")"
        .Range("L8:L" & LR).Formula = "=IFERROR(INDEX(Table1[s.s.disc],MATCH(G8&H8,INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        .Range("M8:M" & LR).Formula = "=IFERROR(K8-K8*L8%,"""")"
        .Range("O8:O" & LR).Formula = "=IFERROR(INDEX(Table1[p.rate],MATCH(G8&H8,INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        .Range("P8:P" & LR).Formula = "=IFERROR(I8*O8,"""")"
        .Range("Q8:Q" & LR).Formula = "=IFERROR(INDEX(Table1[s.p.disc],MATCH(G8&H8,INDEX(Table1[PRODUCT]&Table1[COLOR],0),0)),"""")"
        .Range("R8:R" & LR).Formula = "=IFERROR(P8-P8*Q8%,"""")"
    End With
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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