Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Inserting 3 rows in between 1700 and 1900 time

0

hello

Thank you for looking at my post

I am wanting to insert 3 rows automatically down a large data set 

It is between the 1700 and 1900 hour

Currently I do this manually which is time consuming

In relation to the large data set I am seeking to do this on the fly (instantly)

Attached find a sample 

Thank You So Much

Answer
Discuss

Discussion


You posted a question Nov. 17 and John and I both provided an answer to which your response was "I will work with this and see the results" to each of us. No other comment. Neither answer selected.
Your question on Feb. 4 you didn't resond at all to either John's or mine question.

Because of this, not following forum rules, I don't know if I will be putting much effort (if any) into providing an answer.

If you really want an answer and are willing to follow the forum rules, respond to this comment.
WillieD24 (rep: 723) Apr 23, '24 at 11:07 pm
I share Willie's view above so won't attempt to reply to yiur question until you comment on Willie's podt above 
John_Ru (rep: 6792) Apr 24, '24 at 10:04 am
@Makingadifference

No response, comment? I wasn't really expecting one. I did put together a simple solution for you, and all you have to do is provide feedback. If you do I will post my solution. If I do post my solution then you must follow rule #1:
"When you get Answers to your Question you must reply or select the best one using the Select Answer button under the Answer."
It's all up to you.
WillieD24 (rep: 723) Apr 30, '24 at 11:40 pm
@Makingadifference
If you are willing to answer my questions below ( 1: How large is the data set? 100 rows? 1,000 rows? 10,000 rows?   2: How many times do 3 rows need to be added?) regarding adding 3 rows then I will share my solution.
WillieD24 (rep: 723) Jul 24, '25 at 7:57 pm
Add to Discussion

Answers

0

 hi, please try following vba code for your problem

Sub InsertThreeRowsBetween1700And1900_ColumnPrompt()

    Dim ws As Worksheet

    Set ws = ActiveSheet

    Dim colLetter As String

    colLetter = InputBox("Enter the column letter where the time values are (e.g., A, B, C):", "Select Time Column")

    If colLetter = "" Then

        MsgBox "Operation cancelled."

        Exit Sub

    End If

    Dim colNum As Long

    colNum = Columns(colLetter & ":" & colLetter).Column

    Dim lastRow As Long

    lastRow = ws.Cells(ws.Rows.Count, colNum).End(xlUp).Row

    Dim i As Long

    Application.ScreenUpdating = False

    Application.Calculation = xlCalculationManual

    ' Loop from bottom to top

    For i = lastRow - 1 To 1 Step -1

        Dim time1 As Variant, time2 As Variant

        time1 = ws.Cells(i, colNum).Value

        time2 = ws.Cells(i + 1, colNum).Value

        If Format(time1, "hh:mm") = "17:00" And Format(time2, "hh:mm") = "19:00" Then

            ws.Rows(i + 1).Resize(3).Insert Shift:=xlDown

        End If

    Next i

    Application.Calculation = xlCalculationAutomatic

    Application.ScreenUpdating = True

    MsgBox "3 rows inserted between 17:00 and 19:00 in column " & colLetter & "."

End Sub

Discuss

Discussion

@Amit,

If you look at past comments above you will see this poster does not provide feedback and that is why I won't attempt providing a solution. You shouldn't expect any feedback either. Also, it seems obvious that Makingadifference Has edited/over-written the April 2024 post to create this post rather than start a new post.

Your solution is good but will only add the 3 rows once. In the sample file provided there are at least 2 instances where the extra 3 rows are required. Unfortunately Makingadifference hasn't provided enough information/details. Such as: How large is the data set? 100 rows? 1,000 rows? 10,000 rows?   How many times do 3 rows need to be added?

Good Luck.

Cheers   :-)
WillieD24 (rep: 723) Jul 20, '25 at 11:27 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login