+ Reply to Thread
Results 1 to 17 of 17

Using macro to find first empty cell in column. If range is empty returns error.

  1. #1
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Using macro to find first empty cell in column. If range is empty returns error.

    Hi,
    I am using this macro to take me to the first empty cell in column C, run from a shape button. “Range("C208").End(xlDown).Offset(1, 0).Select” Which is working great.
    My little problem is when there is not any data entered in column C it returns a Run Time Error.
    All I want is a message box to say “No data entered for this month” rather than the error message
    I have tried google but for some reason can not find anything that works for me.

    Error is application defined or object defined error 1004

    Many thanks in advance.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Sintek, Thank you for your reply. I am really sorry but I have not given you enough info for my worksheet.

    I have 12 buttons and 12 different macros, 1 for each month which applies to different areas of column C. I need to look at earlier months rather than just the last entry.

    Range("C4").End(xlDown).Offset(1, 0).Select
    Range("C206").End(xlDown).Offset(1, 0).Select
    Range("C408").End(xlDown).Offset(1, 0).Select
    Range("C610").End(xlDown).Offset(1, 0).Select
    Range("C812").End(xlDown).Offset(1, 0).Select
    Range("C1014").End(xlDown).Offset(1, 0).Select
    Range("C1216").End(xlDown).Offset(1, 0).Select
    Range("C1418").End(xlDown).Offset(1, 0).Select
    Range("C1620").End(xlDown).Offset(1, 0).Select
    Range("C1822").End(xlDown).Offset(1, 0).Select
    Range("C2024").End(xlDown).Offset(1, 0).Select
    Range("C2226").End(xlDown).Offset(1, 0).Select

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Using macro to find first empty cell in column. If range is empty returns error.


    Hi !

    Could be done with a single procedure, just if each range has a name or via the property of its button …
    Last edited by Marc L; 05-22-2019 at 10:48 AM. Reason: typo …

  5. #5
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Marc L, Thanks for reply. I have already got named ranges in place for each month, but I don’t know how to do what you suggest!

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Using macro to find first empty cell in column. If range is empty returns error.


    So it depends on your logic for each name …

  7. #7
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Hi Marc L,

    The named ranges I use are,

    Statement_Apr refers to =Statements!$C$4:$C$203
    Statement_May refers to =Statements!$C$206:$C$405
    Statement_Jun refers to =Statements!$C$408:$C$607
    Statement_Jul refers to =Statements!$C$610:$C$809
    Statement_Aug refers to =Statements!$C$812:$C$1011
    Statement_Sep refers to =Statements!$C$1014:$C$1213
    Statement_Oct refers to =Statements!$C$1216:$C$1415
    Statement_Nov refers to =Statements!$C$1418:$C$1617
    Statement_Dec refers to =Statements!$C$1620:$C$1819
    Statement_Jan refers to =Statements!$C$1822:$C$2021
    Statement_Feb refers to =Statements!$C$2024:$C$2223
    Statement_Mar refers to =Statements!$C$2226:$C$2425

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Using macro to find first empty cell in column. If range is empty returns error.


    It's time you attach a workbook, it should be easier for any helper …

  9. #9
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Please see attached workbook
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Please Login or Register  to view this content.
    Would it not be more convenient and easier to maintain if each month had it's own sheet? (Just thinking out loud here)

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ‼

    Quote Originally Posted by A440 View Post
    Please see attached workbook
    With your smart worksheet, you just needs two procedures for all the buttons ! (except Home)
    Remove previous code (except the Home procedure), paste next code
    then affect each procedure to corresponding buttons and enjoy !

    Paste these procedures to the Sheet36(Statements) worksheet module :

    PHP Code: 
    Sub FirstBlank()
            
    Application.Caller:  If IsError(VThen Exit Sub
        With Range
    ("Statement_" Me.Shapes(V).TextFrame.Characters.Text)
            If 
    IsEmpty(.Cells(1)) Then .Cells(1).Select Else .Cells(.Count)(2).End(xlUp)(2).Select
        End With
    End Sub


    Sub NameRange
    ()
        
    Application.Caller:  If IsError(VThen Exit Sub
        Application
    .Goto Range("Statement_" Me.Shapes(V).TextFrame.Characters.Text), True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  12. #12
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Please find the attached and click on the button called "Select First Empty Cell" and then select the Month from the listbox in the UserForm and click OK to select the first empty cell for the selected month.
    See if this is something you can work with.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  13. #13
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    jolivanes, Thanks for the suggestion, the worksheet is a copy from my main file which has to many sheets in it already lol

  14. #14
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    sktneer, Thank you for your reply. Great solution, I have ideas for using this else where as well.

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Using macro to find first empty cell in column. If range is empty returns error.


    You are lucky as sktneer solution works only on computers with english language, not for my local language for example …

  16. #16
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Using macro to find first empty cell in column. If range is empty returns error.

    Marc L, Thank you very much for your code, now using it in my worksheet. I really wish I could take time out to learn vba properly,but hey thankfully there are forums like this to help us out.

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Using macro to find first empty cell in column. If range is empty returns error.


    You're welcome and thanks for the rep' !

+ 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. Find the next non-empty cell in column range
    By Rajendra_kodavaty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2016, 03:40 PM
  2. [SOLVED] How do I find the first empty cell in a range of cells in a column
    By Nirmall in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-12-2015, 01:20 PM
  3. [SOLVED] Find next empty cell (Row)within a specific range in column A
    By JRidge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2014, 05:39 AM
  4. Replies: 5
    Last Post: 05-13-2014, 10:19 AM
  5. Need to find empty filled cells in a column and copy to the empty cell below
    By Grahamfeeley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2014, 10:09 AM
  6. MACRO to empty a range of cells based on whether specified cell is empty
    By TBJV in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2013, 10:35 PM
  7. Macro to Find any empty cell within a range and show result in another column
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2008, 11:32 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