+ Reply to Thread
Results 1 to 21 of 21

macro not working as expected, need someone good at debugging macro's

Hybrid View

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    macro not working as expected, need someone good at debugging macro's

    HELLO ALL,

    So I have this macro that reads a sheet (named A through FFF), which basically copies each sheet to a "master" page, performs some calculations (like adding items up or deleting rows) and then copies the master to a final sheet (called "big master"). with me so far? when i run the macro on just a few pages (like A-F), the routine works like a champ. but when i run in on my big list (A-FFF), then it fails in certain pages (see list below). I have tried recreating the source pages to no avail. i just cant figure out why its doing what its doing. i have included the workbook and most of the problematic sheets (left A which works perfectly, cant upload all the sheets as it makes the file go above 1Mb). the macro that i run is called "grand finale" which isn't so grand now that its not working as expected. i need someone with a critical eye that can deduce what is wrong with my source pages.

    Sheets that dont calc correctly:
    Sheets T, W, Y, Z, AA, HH, II, UU, VV, ZZ, DDD, EEE, FFF (left this one off so that i could get file size under 1mb)

    Estimate Test upload.xlsm

    please rename "estimate test upload" to "estimate test", otherwise the macro will fail. thanks
    Last edited by dmcgov; 12-22-2015 at 08:31 AM. Reason: added reason for renaming upload

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: macro not working as expected, need someone good at debugging macro's

    Rather than all that explanation, it might be more helpful to just include the code, tell us which line it fails on and what the error message is.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    No error message as the routine runs through the paces normallly. so no error's at all. which is why i included the workbook, its the only way to see what is not happening. when you look at exhibit A (fixture 001) it correctly puts all the info on big master, but then it fails on the sheets listed in the OP.

    so can anyone help me?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: macro not working as expected, need someone good at debugging macro's

    Hello dmcgov,

    There is quite a bit of code that needs to be looked at. I wouldn't expect anyone to respond right away. It may take a day or two for someone to locate the problem.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    ok, ill wait. i just cant figure out why its not working. most of the tabs are good. but the ones that dont work. i just dont know.

    thanks for all your help.

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    so one place the macro fails is during this code:

    With Sheets("master")
        lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
        lastcolumn = .Cells(5, Columns.Count).End(xlToLeft).Column
        .Range(.Cells(2, "A"), .Cells(lastrow, lastcolumn)).Copy
            If Sheets("BigMaster").Range("A1") = "" Then
                Sheets("BigMaster").Range("A1").PasteSpecial xlPasteValues
            Else
                Sheets("BigMaster").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
            End If
        End With
    what this section of the code does is to take all of the rows from Master and insert it into BigMaster. but it only copies one column of data, instead of the whole range.

    any ideas?

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    so one place the macro fails is during this code:

    With Sheets("master")
        lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
        lastcolumn = .Cells(5, Columns.Count).End(xlToLeft).Column
        .Range(.Cells(2, "A"), .Cells(lastrow, lastcolumn)).Copy
            If Sheets("BigMaster").Range("A1") = "" Then
                Sheets("BigMaster").Range("A1").PasteSpecial xlPasteValues
            Else
                Sheets("BigMaster").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
            End If
        End With
    what this section of the code does is to take all of the rows from Master and insert it into BigMaster. but it only copies one column of data (this shows up in certain pages), instead of the whole range. i can list the pages that fail this way if necessary.

    any ideas?

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro not working as expected, need someone good at debugging macro's

    Hi dmcgov

    You're missing a couple of dots (.) in these two lines...could be part of the problem.
    lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
    lastcolumn = .Cells(5, Columns.Count).End(xlToLeft).Column
    lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
    lastcolumn = .Cells(5, .Columns.Count).End(xlToLeft).Column
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  9. #9
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    I made the change that you requested and still the same problem with this part of the macro. it only copies one column and not the entire range.

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro not working as expected, need someone good at debugging macro's

    Hi dmcgov,
    try this
    With Sheets("master")
        .Range("A1").CurrentRegion.Offset(1).Copy
        If Sheets("BigMaster").Range("A1") = "" Then
            Sheets("BigMaster").Range("A1").PasteSpecial xlPasteValues
        Else
            Sheets("BigMaster").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
        End If
    End With

  11. #11
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    ok so the next part of the macro needs to copy formulas correctly.

    here is the offending code (there is a lot of it). i will detail what fails during the macro running.

            Set c = Sheets("formulas").Range("j19:j148").Find(ws.Name, lookat:=xlWhole)
            If Not c Is Nothing Then
                Sheets(c.Value).Select
                Range("b2:h329").Select
                Selection.Copy
                Sheets("estimating1").Select
                Range("c2").Select
                'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                ':=False, Transpose:=False
                ActiveSheet.Paste
                'Application.Run "'Estimate Test.xlsm'!dummy1"
                'put dummy1 here
                    Sheets("Estimating1").Select
                    ActiveWindow.SmallScroll Down:=-189
                    Range("C58:D232").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("C2").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Sheets("Estimating1").Select
                    ActiveWindow.SmallScroll Down:=-165
                    Range("G58:I232").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("H2").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=-48
                    Range("O8").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("G2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=IF(RC[-4]=0,0,IF(RC[1]=0,0,IF(RC[3]=0,0,RC[1])))"
                    Range("G3").Select
                    ActiveWindow.SmallScroll Down:=-6
                    Range("G2").Select
                    Selection.AutoFill Destination:=Range("G2:G180"), Type:=xlFillDefault
                    Range("G2:G180").Select
                    ActiveWindow.SmallScroll Down:=-171
                    Selection.Copy
                    Range("A2").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Application.CutCopyMode = False
                'Application.Run "'Estimate Test.xlsm'!removeGRows"
                'put removeGRows here
                    'Application.ScreenUpdating = False
                    filtercolumn = "G"
                    Set wks = wkb.Sheets("master")
                    totalrows = wks.Cells(Rows.Count, "A").End(xlUp).Row
                    For j = totalrows To 1 Step -1
                        If wks.Cells(j, filtercolumn) = 0 Then
                            wks.Rows(j).Delete
                        End If
                    Next j
                    'Application.ScreenUpdating = True
                'Application.Run "'Estimate Test.xlsm'!dummy2"
                'put dummy2 here
                    Selection.ClearContents
                    Range("G2:G241").Select
                    Selection.ClearContents
                    Sheets("Formulas").Select
                    Range("K11:O15").Select
                    Selection.Copy
                    Sheets("Master").Select
                    ActiveWindow.SmallScroll Down:=174
                    Range("C196").Select
                    ActiveSheet.Paste
                    Range("G196").Select
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!sheetgoods"
                    Range("G197").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!solidstock"
                    Range("G198").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!preorderedwood"
                    Range("G199").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!hardware"
                    Range("G200").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!finishing"
                    Range("G201").Select
                    ActiveWindow.SmallScroll Down:=-183
                    Sheets("Formulas").Select
                    Range("O19").Select
                    Sheets("Master").Select
                    Range("P2").Select
                    ActiveCell.FormulaR1C1 = "=Estimating1!R[3]C[-10]"
                    Range("P3").Select
                    ActiveWindow.SmallScroll Down:=-87
                    Range("P2").Select
                    Selection.Copy
                    Range("P2:P200").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=3
                    Range("O19").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("A2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[15],lookupABC123,3,FALSE)"
                    Range("A2").Select
                    Selection.AutoFill Destination:=Range("A2:A200"), Type:=xlFillDefault
                    Range("A2:A200").Select
                    ActiveWindow.SmallScroll Down:=-252
                    Sheets("Formulas").Select
                    Range("O20").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("B2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],lookupROOMS,2,FALSE)"
                    Range("B2").Select
                    Selection.AutoFill Destination:=Range("B2:B200"), Type:=xlFillDefault
                    Range("B2:B200").Select
                    ActiveWindow.SmallScroll Down:=-222
                    Sheets("Formulas").Select
                    Range("O22").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("L2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=IF(RC[-3]>0,1,3)"
                    Range("L2").Select
                    Selection.AutoFill Destination:=Range("L2:L200"), Type:=xlFillDefault
                    Range("L2:L200").Select
                    ActiveWindow.SmallScroll Down:=-285
                    Sheets("Master").Select
                    Range("O2").Select
                    ActiveCell.FormulaR1C1 = "=SUM(C[-5])"
                    Range("O2").Select
                    Selection.Copy
                    Range("O3:O200").Select
                    ActiveSheet.Paste
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=6
                    Range("O27").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("K2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=RC[-8]&"".""&RC[-10]"
                    Range("K2").Select
                    Selection.AutoFill Destination:=Range("K2:K200"), Type:=xlFillDefault
                    Range("K2:K200").Select
                    ActiveWindow.SmallScroll Down:=-228
                    Sheets("Formulas").Select
                    Range("O29").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("N2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=RC[-10]&"".""&RC[-12]"
                    Range("N2").Select
                    Selection.AutoFill Destination:=Range("N2:N200"), Type:=xlFillDefault
                    Range("N2:N200").Select
                    ActiveWindow.SmallScroll Down:=-309
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=6
                    Range("O31").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("J2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=(IF(RC[-3]>0,RC[-3],RC[-1]*RC[-2]))"
                    Range("J2").Select
                    Selection.AutoFill Destination:=Range("J2:J200"), Type:=xlFillDefault
                    Range("J2:J200").Select
                    ActiveWindow.SmallScroll Down:=-174
                    Range("M2").Select
                    ActiveCell.FormulaR1C1 = "=RC[-12]"
                    Range("M2").Select
                    Selection.AutoFill Destination:=Range("M2:M200"), Type:=xlFillDefault
                    Range("M2:M200").Select
                    ActiveWindow.SmallScroll Down:=-228
                    Range("E2").Select
                    ActiveCell.FormulaR1C1 = "1"
                    Range("F2").Select
                    ActiveCell.FormulaR1C1 = "EA"
                    Range("E2:F2").Select
                    Selection.Copy
                    Range("E3:E200").Select
                    ActiveWindow.SmallScroll Down:=-168
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
    when it copies the formulas from the formulas tab, it fails on these lines of code

    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[15],lookupABC123,3,FALSE)"
    and
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],lookupROOMS,2,FALSE)"

    instead of giving the fixture number and name, it comes in as #N/A for both columns.

    any ideas?

  12. #12
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    nilem, gold star for you. that fixed one of the problems with the macro. now on to the next one. i will detail that in the post below.

  13. #13
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro not working as expected, need someone good at debugging macro's

    What is lookupABC123 and lookupROOMS - the named range? variable?

  14. #14
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    its found on the formulas sheet. its a named range. as far as i can tell, it should pull the names and numbers over like it does on most of the sheets.

    thanks for looking at this.

  15. #15
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro not working as expected, need someone good at debugging macro's

    I tested this code in your file
    Sub test()
    Sheets("Master").Range("P2") = "Exhibit D"
    Sheets("Master").Range("A2").FormulaR1C1 = "=iferror(VLOOKUP(RC[15],lookupABC123,3,FALSE),"""")"
    'or
    'Sheets("Master").Range("A2").FormulaR1C1 = "=iferror(VLOOKUP(RC[15],lookupABC123,3,FALSE),""Not found"")"
    End Sub
    and it works for me

  16. #16
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    @nilem, now when i run "grand finale", it leaves off the fixture number (havent fixed the room names yet).

    any idea on why the column A is blank? i will put in the whole macro so you can run that against the workbook.

    Sub GrandFinale()
        For Each ws In ThisWorkbook.Worksheets
        Dim wkb As Workbook
        Dim wks As Worksheet
        Set wkb = ThisWorkbook
        Dim lastcolumn As Long
        Dim lastrow As Long
        Application.DisplayAlerts = False
            Set c = Sheets("formulas").Range("j19:j148").Find(ws.Name, lookat:=xlWhole)
            If Not c Is Nothing Then
                Sheets(c.Value).Select
                Range("b2:h329").Select
                Selection.Copy
                Sheets("estimating1").Select
                Range("c2").Select
                'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                ':=False, Transpose:=False
                ActiveSheet.Paste
                'Application.Run "'Estimate Test.xlsm'!dummy1"
                'put dummy1 here
                    Sheets("Estimating1").Select
                    ActiveWindow.SmallScroll Down:=-189
                    Range("C58:D232").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("C2").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Sheets("Estimating1").Select
                    ActiveWindow.SmallScroll Down:=-165
                    Range("G58:I232").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("H2").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=-48
                    Range("O8").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("G2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=IF(RC[-4]=0,0,IF(RC[1]=0,0,IF(RC[3]=0,0,RC[1])))"
                    Range("G3").Select
                    ActiveWindow.SmallScroll Down:=-6
                    Range("G2").Select
                    Selection.AutoFill Destination:=Range("G2:G180"), Type:=xlFillDefault
                    Range("G2:G180").Select
                    ActiveWindow.SmallScroll Down:=-171
                    Selection.Copy
                    Range("A2").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Application.CutCopyMode = False
                'Application.Run "'Estimate Test.xlsm'!removeGRows"
                'put removeGRows here
                    'Application.ScreenUpdating = False
                    filtercolumn = "G"
                    Set wks = wkb.Sheets("master")
                    totalrows = wks.Cells(Rows.Count, "A").End(xlUp).Row
                    For j = totalrows To 1 Step -1
                        If wks.Cells(j, filtercolumn) = 0 Then
                            wks.Rows(j).Delete
                        End If
                    Next j
                    'Application.ScreenUpdating = True
                'Application.Run "'Estimate Test.xlsm'!dummy2"
                'put dummy2 here
                    Selection.ClearContents
                    Range("G2:G241").Select
                    Selection.ClearContents
                    Sheets("Formulas").Select
                    Range("K11:O15").Select
                    Selection.Copy
                    Sheets("Master").Select
                    ActiveWindow.SmallScroll Down:=174
                    Range("C196").Select
                    ActiveSheet.Paste
                    Range("G196").Select
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!sheetgoods"
                    Range("G197").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!solidstock"
                    Range("G198").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!preorderedwood"
                    Range("G199").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!hardware"
                    Range("G200").Select
                    ActiveCell.FormulaR1C1 = "='Estimate Test.xlsm'!finishing"
                    Range("G201").Select
                    ActiveWindow.SmallScroll Down:=-183
                    Sheets("Formulas").Select
                    Range("O19").Select
                    Sheets("Master").Select
                    Range("P2").Select
                    ActiveCell.FormulaR1C1 = "=Estimating1!R[3]C[-10]"
                    Range("P3").Select
                    ActiveWindow.SmallScroll Down:=-87
                    Range("P2").Select
                    Selection.Copy
                    Range("P2:P200").Select
                    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                        :=False, Transpose:=False
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=3
                    Range("O19").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("A2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    'ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[15],lookupABC123,3,FALSE)"
                    Sheets("Master").Range("A2").FormulaR1C1 = "=iferror(VLOOKUP(RC[15],lookupABC123,3,FALSE),"""")"
                    Range("A2").Select
                    Selection.AutoFill Destination:=Range("A2:A200"), Type:=xlFillDefault
                    Range("A2:A200").Select
                    ActiveWindow.SmallScroll Down:=-252
                    Sheets("Formulas").Select
                    Range("O20").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("B2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],lookupROOMS,2,FALSE)"
                    Range("B2").Select
                    Selection.AutoFill Destination:=Range("B2:B200"), Type:=xlFillDefault
                    Range("B2:B200").Select
                    ActiveWindow.SmallScroll Down:=-222
                    Sheets("Formulas").Select
                    Range("O22").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("L2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=IF(RC[-3]>0,1,3)"
                    Range("L2").Select
                    Selection.AutoFill Destination:=Range("L2:L200"), Type:=xlFillDefault
                    Range("L2:L200").Select
                    ActiveWindow.SmallScroll Down:=-285
                    Sheets("Master").Select
                    Range("O2").Select
                    ActiveCell.FormulaR1C1 = "=SUM(C[-5])"
                    Range("O2").Select
                    Selection.Copy
                    Range("O3:O200").Select
                    ActiveSheet.Paste
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=6
                    Range("O27").Select
                    Application.CutCopyMode = False
                    Selection.Copy
                    Sheets("Master").Select
                    Range("K2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=RC[-8]&"".""&RC[-10]"
                    Range("K2").Select
                    Selection.AutoFill Destination:=Range("K2:K200"), Type:=xlFillDefault
                    Range("K2:K200").Select
                    ActiveWindow.SmallScroll Down:=-228
                    Sheets("Formulas").Select
                    Range("O29").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("N2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=RC[-10]&"".""&RC[-12]"
                    Range("N2").Select
                    Selection.AutoFill Destination:=Range("N2:N200"), Type:=xlFillDefault
                    Range("N2:N200").Select
                    ActiveWindow.SmallScroll Down:=-309
                    Sheets("Formulas").Select
                    ActiveWindow.SmallScroll Down:=6
                    Range("O31").Select
                    Selection.Copy
                    Sheets("Master").Select
                    Range("J2").Select
                    ActiveSheet.Paste
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                    ActiveCell.FormulaR1C1 = "=(IF(RC[-3]>0,RC[-3],RC[-1]*RC[-2]))"
                    Range("J2").Select
                    Selection.AutoFill Destination:=Range("J2:J200"), Type:=xlFillDefault
                    Range("J2:J200").Select
                    ActiveWindow.SmallScroll Down:=-174
                    Range("M2").Select
                    ActiveCell.FormulaR1C1 = "=RC[-12]"
                    Range("M2").Select
                    Selection.AutoFill Destination:=Range("M2:M200"), Type:=xlFillDefault
                    Range("M2:M200").Select
                    ActiveWindow.SmallScroll Down:=-228
                    Range("E2").Select
                    ActiveCell.FormulaR1C1 = "1"
                    Range("F2").Select
                    ActiveCell.FormulaR1C1 = "EA"
                    Range("E2:F2").Select
                    Selection.Copy
                    Range("E3:E200").Select
                    ActiveWindow.SmallScroll Down:=-168
                    ActiveSheet.Paste
                    Application.CutCopyMode = False
                'Application.Run "'Estimate Test.xlsm'!removeJRows"
                'put removeJRows here
                    'Application.ScreenUpdating = False
                    'Dim wkb As Workbook
                    'Dim wks As Worksheet
                    'Set wkb = ThisWorkbook
                    filtercolumn = "J"
                    Set wks = wkb.Sheets("master")
                    totalrows = wks.Cells(Rows.Count, "A").End(xlUp).Row
                    For j = totalrows To 1 Step -1
                        If wks.Cells(j, filtercolumn) = 0 Then
                            wks.Rows(j).Delete
                        End If
                    Next j
                    Application.ScreenUpdating = True
                'Application.Run "'Estimate Test.xlsm'!dummy6"
                'put dummy6 here
                    'Dim lastcolumn As Long
                    'Dim lastrow As Long
                    'With Sheets("master")
                    'lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
                    'lastcolumn = .Cells(5, Columns.Count).End(xlToLeft).Column
                    'lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
                    'lastcolumn = .Cells(5, .Columns.Count).End(xlToLeft).Column
                    '.Range(.Cells(2, "A"), .Cells(lastrow, lastcolumn)).Copy
                    '    If Sheets("BigMaster").Range("A1") = "" Then
                    '        Sheets("BigMaster").Range("A1").PasteSpecial xlPasteValues
                    '    Else
                    '        Sheets("BigMaster").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
                    '
                    '    End If
                    'End With
                    With Sheets("master")
                        .Range("A1").CurrentRegion.Offset(1).Copy
                        If Sheets("BigMaster").Range("A1") = "" Then
                            Sheets("BigMaster").Range("A1").PasteSpecial xlPasteValues
                        Else
                            Sheets("BigMaster").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
                        End If
                    End With
    
                'If c = "U" Then Exit Sub
            End If
            'ans = MsgBox("ok to proceed to next fixture?", vbYesNo)
            'If ans = vbNo Then Exit Sub
            Next
            'MsgBox "ok to proceed to next fixture?"
        Application.DisplayAlerts = True
    End Sub
    dont forget to rename the workbook, it should be "estimate test" and not "estimate test upload".
    Last edited by dmcgov; 12-22-2015 at 01:33 PM. Reason: added filename rename

  17. #17
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    my general thinking is that there must be something corrupt on the individual sheets though i cant point out where this would be. the macro runs fine on 75% of the sheets. so if i take sheet z and copy it to zz, then it works just fine. if i restore the old zz, then it fails. not sure of how to proceed.

  18. #18
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro not working as expected, need someone good at debugging macro's

    Hi dmcgov,
    I do not really understand the essence of your macro, but try this
    Sub GrandFinale()
    Dim ws As Worksheet, c As Range, j As Long
    Application.ScreenUpdating = False
    
    For Each ws In ThisWorkbook.Worksheets
        Set c = Sheets("formulas").Range("j19:j148").Find(ws.Name, lookat:=xlWhole)
        If Not c Is Nothing Then
            Sheets(c.Value).Range("b2:h329").Copy Sheets("estimating1").Range("c2")
    
            With Sheets("master")
    
                Sheets("Estimating1").Range("C58:D232").Copy
                .Range("C2").PasteSpecial Paste:=xlPasteValues
    
                Sheets("Estimating1").Range("G58:I232").Copy
                .Range("H2").PasteSpecial Paste:=xlPasteValues
                                        
                .Range("G2:G180").FormulaR1C1 = "=IF(RC[-4]=0,0,IF(RC[1]=0,0,IF(RC[3]=0,0,RC[1])))"
                .Range("A2:A180").Value = .Range("G2:G180").Value
    
                For j = .Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
                    If .Cells(j, "G") = 0 Then .Rows(j).Delete
                Next j
                .Range("G2:G241").ClearContents
    
                .Range("P2:P200").Value = Sheets("Estimating1").Range("F5").Value
                .Range("A2:A200").FormulaR1C1 = "=IFERROR(VLOOKUP(RC[15],lookupABC123,3,FALSE),"""")"
                .Range("B2:B200").FormulaR1C1 = "=VLOOKUP(RC[-1],lookupROOMS,2,FALSE)"
                .Range("L2:L200").FormulaR1C1 = "=IF(RC[-3]>0,1,3)"
                .Range("O2:O200").FormulaR1C1 = "=SUM(C[-5])"
                .Range("K2:K200").FormulaR1C1 = "=RC[-8]&"".""&RC[-10]"
                .Range("N2:N200").FormulaR1C1 = "=RC[-10]&"".""&RC[-12]"
                .Range("J2:J200").FormulaR1C1 = "=(IF(RC[-3]>0,RC[-3],RC[-1]*RC[-2]))"
                .Range("M2:M200").FormulaR1C1 = "=RC[-12]"
    
                .Range("E2:E200").Value = "1"
                .Range("F2:F200").Value = "EA"
    
                For j = .Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
                    If .Cells(j, "J") = 0 Then .Rows(j).Delete
                Next j
    
                .Range("A1").CurrentRegion.Offset(1).Copy
                If Sheets("BigMaster").Range("A1") = "" Then
                    Sheets("BigMaster").Range("A1").PasteSpecial xlPasteValues
                Else
                    Sheets("BigMaster").Range("A" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
                End If
                Application.CutCopyMode = False
            End With
    
        End If
    Next ws
    Application.ScreenUpdating = True
    
    End Sub
    Have you observed Falkon9 landing in Florida? Probably, it is amazing.

  19. #19
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    @nilem, yup, same problem, either blank in column A or NA in column B. any thoughts?

  20. #20
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro not working as expected, need someone good at debugging macro's

    Look at the Sheet "W" cell D5. There is space (gap) at the end of the word "Exhibit W", remove this space. Do the same thing with a sheet "AA" and "HH"

  21. #21
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: macro not working as expected, need someone good at debugging macro's

    Wow, glad you have a critical eye! Gold Stars for you... i'll be marking this as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro template good saved but running macro with imported data problem
    By brazilexcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2015, 10:42 PM
  2. [SOLVED] Help debugging macro
    By kellynicolebarrett in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-16-2014, 09:17 AM
  3. Specific line of my macro isnīt working as expected
    By Marceltcm in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-30-2013, 11:47 AM
  4. [SOLVED] Debugging a macro
    By jharaldson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2013, 01:52 PM
  5. MACRO debugging but working in specific istances
    By ska87RA in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-05-2013, 08:19 AM
  6. [SOLVED] Macro debugging
    By VelvetRevolver84 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-01-2013, 06:14 PM
  7. Help please in debugging this macro
    By sungen99 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-23-2006, 11:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1