+ Reply to Thread
Results 1 to 7 of 7

Insert blank row after max value less than X

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2017
    Location
    Oregon, USA
    MS-Off Ver
    2010
    Posts
    13

    Insert blank row after max value less than X

    Hello,
    Please forgive me. I'm a new VBA user and can't figure this out.

    I have a list that looks like this:

    106
    108
    110
    201
    202
    203 .... etc,

    I need a vba code that finds the maximum value that is less than 200, and inserts a blank row below it. If there is no value less than 200, do nothing.

    Please and Thank you!

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Insert blank row after max value less than X

    Try this:-
    Sub MG19Aug07
    Dim Rng As Range, Dn As Range, Temp As Range
    Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    Set Temp = Rng(1)
    For Each Dn In Rng
        If Dn.Value < 200 And Dn.Value > Temp Then Set Temp = Dn
    Next Dn
    Temp.Offset(1).EntireRow.Insert
    End Sub
    Regards Mick

  3. #3
    Registered User
    Join Date
    07-08-2017
    Location
    Oregon, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Insert blank row after max value less than X

    It works! Thank you so much!

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Insert blank row after max value less than X

    You're welcome

  5. #5
    Registered User
    Join Date
    07-08-2017
    Location
    Oregon, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Insert blank row after max value less than X

    Thank you so much, MickG, for helping me with this piece of code. However, I wonder if you could help me with an issue I'm now seeing. The code works perfectly for inserting a blank line beneath the max value <200. However, if there is no value <200, say, my list begins with 200 and up, it inserts a blank line after the first number >200. I don't want any lines inserted beneath numbers >200. Any ideas?
    Last edited by Veroshima; 09-09-2017 at 06:43 AM.

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Insert blank row after max value less than X

    Try this:-
    Sub MG09Sep24
    Dim Rng As Range, Dn As Range, Temp As Range, Num As Long
    Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Dn.Value < 200 And Dn.Value > Num Then
            Set Temp = Dn: Num = Dn
        End If
    Next Dn
    If Num > 0 Then Temp.Offset(1).EntireRow.Insert
    End Sub
    Regards Mick

  7. #7
    Registered User
    Join Date
    07-08-2017
    Location
    Oregon, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Insert blank row after max value less than X

    Works lovely! You are an angel! Thank you.

+ 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. Table that insert measures and insert blank rows
    By searme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2016, 04:49 AM
  2. [SOLVED] Auto insert blank row. (blank copy of row that includes merged cells)
    By rutts in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-22-2013, 07:48 PM
  3. [SOLVED] Macro to copy row, insert below, invert amt, and insert blank row between each new tx
    By raquel1227 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-07-2013, 12:56 PM
  4. Insert blank row, sum and insert page break macro
    By kim5012 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2012, 01:46 AM
  5. How to remove blank rows, then insert blank row conditionally, PLUS error proof
    By GTS115 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2009, 11:39 AM
  6. Macro to insert copy and insert formulas only to next blank row
    By bob in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-30-2006, 07:10 AM
  7. [SOLVED] Macro code to test for blank row and insert blank row if false
    By Mattie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2006, 08:25 PM

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