+ Reply to Thread
Results 1 to 8 of 8

Macro "IF" to insert a row.

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Macro "IF" to insert a row.

    Just had a thought. I need to add a line of code to check to see if there is a blank row after row 4, (between rows 4 and 6 I need a blank), and insert one of there isn't.

    By the way, I know I've been full of questions. If you feel I'm abusing the forum. let me know.

    Later,

    Jerry.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hutch, thanks for asking questions -- that's why we're here!! We always appreciate if users have taken the time to look for answers themselves first, but we enjoy helping others so that's what I'll do..

    This macro may suit you. It quicky checks through each cell in row 5, and if it finds any that aren't blank it inserts a new row 5 and shifts everything else down 1 row.
    Please Login or Register  to view this content.
    If you need it to actually delete the row instead of inserting one, that can be done, too.

    Hope that helps!

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Still needs tweaking...

    Thanks, Paul. I've still got a small problem. When I run your code on a sheet in which row 5 is blank, it runs great, but when there is data in row 5, it inserts the new row, as needed, but then it stops the macro.

    If row 5 is blank, I just want it to run the rest of the macro. If not, I want to insert a blank row after row 4, and then continue to run the macro.

    Thanks for any help you can offer.

    Here's the first part of the code:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Try changing "Exit Sub" to "Exit For"

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Good to Go

    That fixed 'er right up, Paul. Thanks again for the help.

    Hutch.

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

    Please Login or Register  to view this content.
    Hope that helps.

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

    Free DataBaseForm example

  7. #7
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    That works, too...

    That works just as well, Roy. I notice there are always bunches of different ways to do things in VBA, unfortunatley, I don't know any of them.

    Thanks again for all your help, guys.

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You will learn, just stick around.

    I think it's best to avoid loops for faster code.

+ 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