+ Reply to Thread
Results 1 to 12 of 12

find data not used, find last row and paste(stuck on last part! pls help)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    find data not used, find last row and paste(stuck on last part! pls help)

    Hi all, I am so grateful for everyone's help here on this board as it took me a far way!

    I am working on building summary database which utalizes 2 different data spreadsheets and currently am stuck on last part. I am attaching what I have put together so far, and added detailed notes what I am trying to accomplish inside..

    to give quick overview, I have 3 excel tabs:
    -total_Summary (where I summarize profits anything for (this month+previous month) and anything that has (nothing for this month but has for previous months)
    -this_month_profit
    -prior_months_profits

    "prior_months_profits" contains information for past 2 years.. every month we sweep monthly data to "prior_months_profits".. to track profits, I combine current month profits with any previous month profits.. any remaining items in prior month profits which has no current month profits I still need to reflect..this is the part where I got stuck.. as I need to find the data, seperate it and then paste it in my summary tab on the last row after where I combined current month with any data that matches to previous month.

    I know this might be little confusing, so I made it little more user friendly in the attached file.

    Please if anyone could help with some feedback or suggestions it would be greatly appreciated.

    Thanks so much

    Dan
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    I've looked at your code & I would suggest you review it. It's rarely necessary to activate/select objects in VBA. Your code constantly activates the workbook & selects sheets & ranges. For example
    Sub test()
    
    Dim LastRow As Long
    LastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
    
    'CLEAR OLD DATA
        Windows("Testing.xls").Activate
        Sheets("total_summary").Select
        Range("A3:G" & LastRow).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.ClearContents
       
    'copy paste ACCOUNT NUMBER
        Windows("Testing.xls").Activate
        Sheets("this_month_profit").Select
        Range("A3:A" & LastRow).Select
        Selection.Copy
        Windows("testing.xls").Activate
        Sheets("total_summary").Select
        Range("A3").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    This amendment will work more efficiently

    
    Option Explicit
    Sub test()
    
        Dim LastRow As Long
    
    
        'this is pointless it will only work on the active sheet
        'LastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
    
        'CLEAR OLD DATA
        With Sheets("total_summary")
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
            .Range(.Cells(3, 1), .Cells(LastRow, 7)).ClearContents
        End With
        'copy paste ACCOUNT NUMBER
        With Sheets("this_month_profit")
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
            .Range(.Cells(3, 1), .Cells(LastRow, 1)).Copy Sheets("total_summary").Cells(3, 1)
        End With
    'rest of code needs changing
    I'm not 100% sure what you are actually asking but I'll take a look later
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    thanks for the tips Roy.. this is great.. really appreciate it..

    I know my notes might be little confusing, so please let me know if there is anything I can clarify.. I tried to make it little more detailed in the actual attached spreadsheet

    thanks again

    Dan

  4. #4
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    Roy, the code you changed works great..one question.. what is

    Option Explicit
    any feedback on the attached file where i need to find and bring in remaining data to last row?

    thanks so much

    Dan

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    I'm finishing a project at the moment, I'll have a look as soon as I can

    Option Explicit forces you to declare Variables, see this

  6. #6
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    This is very helpful link. Thanks!
    No worries about the attachment.. Whenever you have some time. Thanks again!

    Dan

  7. #7
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    Hi Roy, I am working on amending the code you sent me and running into some trouble..

    I should of clarified this, I am copying/pasting data by telling VBA to open one Worksheet(this_month_profit),copy data and then paste data into my different Worksheet(Total_Summary). (I had 3 tabs on my attachment for convenience but should of clarified it)1) Open my original spreadsheet and clear everything..(this is all good and works)

    With Sheets("total_summary")
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
            .Range(.Cells(3, 1), .Cells(LastRow, 7)).ClearContents
        End With
    This is where I get stuck... I need to switch back to this_month_profit workbook.. this is why I had below code:
    'copy paste ACCOUNT NUMBER
        Windows("this_month_profit_workbook.xls").Activate
        Sheets("this_month_profit").Select
        Range("A3:A" & LastRow).Select
        Selection.Copy
        Windows("testing.xls").Activate
        Sheets("total_summary").Select
        Range("A3").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

    Is there a way to incorporate in the code you provided me below? If I understand correctly, the below code, only assumes to switch between different tabs?
    With Sheets("this_month_profit")
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
            .Range(.Cells(3, 1), .Cells(LastRow, 1)).Copy Sheets("total_summary").Cells(3, 1)
        End With

  8. #8
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    Hi everyone, just figured will bump the post.. was wondering if anyone had any comments on below..Any advice is very appreciated!

    thanks so much
    Danny

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    I'll take a look later

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    Can you attach the latest workbook?

  11. #11
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    Hi Roy, let's scratch everything from above..basically to summarize everything I am attaching amended workbooks.. thanks again so much for your time with this..

    1) testing.xls
    2) this_month.xls (need to change dir name in VBA wherever you save this)

    if you run the macro I put together it works fine( at least I think so.. I know it needs some tweaking to make it more effcient).

    What I am more concerned is the part that I am stuck on hehe...So I pulled all the profits for this month and matched to any profits with previous months based per "Account Number" and "ID"

    Now, I need to find any remaining profits in Prior_month_Profits tab that I did not match with Current Month per account number and ID and transfer them to column G.. (after you run the macro, and look in prior_month_profits tab I highlighted remaining items in red)

    the spreadsheet I attached I think breaks it down little bit better
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    08-31-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    204

    Re: find data not used, find last row and paste(stuck on last part! pls help)

    Hi Roy, how is it going? not to bug you.. just curious if you had any comments

    Thanks! Danny

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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