Consulting

Results 1 to 4 of 4

Thread: Solved: Help to copy the formula

  1. #1
    VBAX Tutor
    Joined
    Sep 2009
    Posts
    231
    Location

    Solved: Help to copy the formula

    Hi ,
    Am trying to used this code to be place in a range but a having an error like this :

    Application-defined or object-defined error

    here is my code :

    [VBA]Sub OverBook_Formula()
    starttime = Timer
    Dim lLR As Long

    Sheets("loading").Activate
    ActiveSheet.Unprotect

    LR = Cells(Rows.Count, "D").End(xlUp).Row


    With ThisWorkbook.Sheets("loading").Range("AA53:AY" & LR)

    .Formula = "=IF(OR($H53="",$R53="",$M53=""),0,IF(AA$51<$L53,0,IF(AA$51>=$L53,IF(0<($S5 3),MIN(($S53-SUM(Z53:$Z53)),$T53,SUMIF($Y$3:$Y$20,$Y53,AA$3:AA$20)))))) "




    End With





    End Sub[/VBA]

    can i please have a guide on that.
    thanks.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.


    [VBA]
    Sub OverBook_Formula()

    Dim LR As Long

    starttime = Timer

    With Sheets("loading")
    .Unprotect
    LR = .Cells(Rows.Count, "D").End(xlUp).Row
    .Range("AA53:AY" & LR).Formula = "=IF(OR($H53="""",$R53="""",$M53=""""),0,IF(AA$51<$L53,0,IF(AA$51>=$L53,IF( 0<($S53),MIN(($S53-SUM(Z53:$Z53)),$T53,SUMIF($Y$3:$Y$20,$Y53,AA$3:AA$20))))))"
    End With

    End Sub
    [/VBA]
    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 Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    1. You can use macro recorder. And write your formula in Excel. VBA will give R1C1 style formula. Its readability could be an issue as we are more used to reading A1 styled references more.

    2. The other option is copy the formula from Excel and paste it in VBA.
    [VBA]=IF(OR($H53="",$R53="",$M53=""),0,IF(AA$51<$L53,0,IF(AA$51>=$L53,IF(0<($S53 ),MIN(($S53-SUM(Z53:$Z53)),$T53,SUMIF($Y$3:$Y$20,$Y53,AA$3:AA$20))))))[/VBA]
    Select this string and then do find and replace [Toggle on "Selected Text" option]:
    FIND : "
    REPLACE : ""
    and then wrap it with double quotes. It will look like the formula Macubus provided.
    [VBA].Formula = "=IF(OR($H53="""",$R53="""",$M53=""""),0,IF(AA$51<$L53,0,IF(AA$51>=$L53,IF( 0<($S53),MIN(($S53-SUM(Z53:$Z53)),$T53,SUMIF($Y$3:$Y$20,$Y53,AA$3:AA$20))))))"[/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  4. #4
    VBAX Tutor
    Joined
    Sep 2009
    Posts
    231
    Location
    hi Both,

    thanks a lot i have understand it now that it shall have always double quotes.
    it solved.

    mnay thanks again.

Posting Permissions

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