+ Reply to Thread
Results 1 to 24 of 24

Find First blank cell starting from the top

  1. #1
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Find First blank cell starting from the top

    I am trying to write a macro that will insert a function across multiple columns, but I want to put it one row down from the last used row starting from the top. I have data on A1000, so counting from the bottom up will put my formulas on Row 1002. Instead, how do I get it to insert at the first blank row from the top? Basically, I have between 10-300 rows of data, then nothing else except for A1000. If my last full row is Row 8, how can I insert my formula on row 10? Below is my current macro.

    Please Login or Register  to view this content.
    Last edited by mturnertombow; 12-13-2013 at 05:55 PM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Find First blank cell starting from the top

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    I think this might be faster and still get the results you're after. It simply starts looking "up" at row 999 instead of the bottom of the workbook. It then inserts the proper formulas into columns D:AM two rows below the last used row. It also limits the Sumproduct formula to just the used data cells in each column (I assumed row 1 has headers, so set it to start in row 2). This vastly improves the speed of the formula insertion/calculations.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    You're two for two, Paul. I really appreciate it; I didn't know you could stack those Ranges together like that instead of doing it for each one.
    Is it possible to then copy that whole range, and re-paste it as a value? I have summary sheet that already takes forever to calculate, and when I add those lines in, it freezes my whole computer.
    Last edited by Paul; 12-13-2013 at 03:25 PM. Reason: Removed quote of previous post

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    To copy the row of formulas and paste elsewhere as values, would simply be
    Please Login or Register  to view this content.
    You'd want to put that into the For/Next loop so it's performed for each worksheet. You'd have to change the reference to cell A5 on the Summary sheet of course, likely by finding the next available row on the Summary sheet each iteration through the loop. If you run into trouble doing that let us know.

  6. #6
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    I'm sorry, I meant that I wanted to paste that range of values in the same range. Would it be
    Please Login or Register  to view this content.
    I want it to calculate that, then paste the values. That way, it takes a minute to process the insertion, then it's all values so that when you save it, it doesn't try to calculate on my Summary page, then do that SumProduct for all those rows in each sheet.

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    You missed the PasteSpecial method, but yes, that's all you need to do in that case.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    That was incredibly fast. Thank you so much for your help!

  9. #9
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    How can I make it do that but for only one sheet at a time? I will sometime only need it for one sheet, and I'd like to make a button for it for other users.

    Also, is it possible to, upon closing, make it look at those ranges and delete it? If not, we can just delete that row before recalculating.

  10. #10
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    Can you clarify?

    How can you make it do what for only one sheet at a time? The entire macro (adding formulas in proper row, formatting & pasting as values) or just the pasting values bit? Upon closing, you want to delete the summary values created from all worksheets (the Dx:AMx ranges)? If you're copying that info to the summary sheet, it would make more sense to include that copy in the code loop, as well as deleting the values afterward from each sheet.

  11. #11
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    The below code does what I was asking (I had to move some cells around). I needed it to add formulas, format and paste values for each sheet. When I run it though, it pastes all the values correctly, but it pops up with a title box that says "Microsoft Visual Basic for Applications" and a red X with 400 written beside it. It doesn't seem to effect the code, though.
    http://i.imgur.com/dNwVAlu.png


    Please Login or Register  to view this content.

  12. #12
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    Error in the code?
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    I didn't see that. It works perfectly. Thanks so much again, Paul. Now to add a Macro button to run that Macro to each of my 42 Sheets that will need it!

  14. #14
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    It would probably be easier to create one macro, referencing "ActiveSheet" as you've done, but put it in a standard module. Then in each sheet create a button that simply calls that one macro. Would be a lot more efficient than having that code 42 times.

  15. #15
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    That's what I meant. It all makes sense in my head...

    Each of the 42 sheets will get a button. That button will run Add_Costs macro...Hopefully that makes sense.

  16. #16
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    Sounds right to me.

    Glad you've got it sorted out.

  17. #17
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    Almost all sorted out...
    That code is putting the values one cell to the left. For instance, when it pastes the code, it gives the Total of Column D under Column C. How can I make it look at the correct column?

  18. #18
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    Because your code specifically points to column C in every line (and column B in another) when your previous code was looking at columns C and D?
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    So now, whatever I had in C is now in AM.

    C is now my first column with quantity (runs through AL), where cost is now in AM. B contains a text description, not a value.

    What does the D2:D point to in
    Please Login or Register  to view this content.

  20. #20
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    In your original code, you checked to see if C3 (column C) of the last row (+2) was blank, and if so you started entering formulas to the right of that - in columns D:AM. Your SUMPRODUCT formula multiplied each columns' value against the value in column C and then added them up.

    Your latest code is now checking column B for the blank and starting to put formulas in C:AL. The SUMPRODUCT formula itself, though, is pointing to the original columns. My guess is that if you want to have your formulas in C:AL and sum their products with column AM, then change the D2:D bit to C2:C. So the formula in, say, C20, will be a sumproduct between C2:C18 and AM2:AM18. In D20, the sumproduct would be between D2:D18 and AM2:AM18, and so on.

  21. #21
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    So you're proved correct again. Now I get that same 400 message from earlier though, using code below:
    Please Login or Register  to view this content.

  22. #22
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Find First blank cell starting from the top

    Try fixing the ":A:" to ":AL" in the Copy line again.

  23. #23
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    I promise I'm usually smarter than that. That fixed it. Thank you so much for your help all day, Paul!

  24. #24
    Registered User
    Join Date
    05-24-2013
    Location
    London, England (it's a lie!)
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Find First blank cell starting from the top

    Is it possible to use that same "LR = ActiveSheet.Range("A999").End(xlUp).Row + 2" to make it look at the row there, and then have it delete that row, then run that formula? That way, if there is a button for each sheet, it will delete any previously ran Add_Costs macro lines, and then run that whole formula again and basically just update the numbers that are on there?

+ 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. Count 52 Cells Starting From First Non Blank Cell In Range
    By Caedmonball19 in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 08-20-2013, 12:23 PM
  2. Since when does AdvancedFilter not work if a starting cell is blank?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2013, 08:27 PM
  3. [SOLVED] Copy or Move rows starting with a particular cell value until next blank row
    By sborda in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2012, 07:53 AM
  4. [SOLVED] Find first non-blank cell after a group of blanks copy offset cells, find next blank, loop
    By gwsampso in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-21-2012, 06:11 AM
  5. [SOLVED] How do I find a cell starting with a specific letter?
    By Bking in forum Excel General
    Replies: 5
    Last Post: 07-18-2005, 01:05 AM

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