Add blank line after cell value has changed

richertt

New Member
Joined
Sep 1, 2018
Messages
14
Hi Guys,

I have a timeclock dump of data where column "A" = a person's name and column "B" is their clock in / clock out times. I want to add a blank line between each group of names. Searching google, I found this bt of code...

Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "ADD A LINE"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For i = WorkRng.Rows.count To 2 Step -1
If WorkRng.Cells(i, 1).Value <> WorkRng.Cells(i - 1, 1).Value Then
WorkRng.Cells(i, 1).EntireRow.Insert
End If
Next
Application.ScreenUpdating = True

This works great except it prompts me to select the column to make it work (column A). The names are always in column A. How do I modify the code to automatically select column "A"?

Thanks in advance,

Troy
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Code:
Sub AddRows()
   Dim i As Long
   
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Cells(i, 1) <> Cells(i - 1, 1) Then Rows(i).Insert
   Next i
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Oops! Fluff has already answered. :)
 
Last edited:
Upvote 0
Hello Guys and Gals,

Fluff fixed my first problem. Hopefully someone can help me with my second challenge....

What if I wanted to change the color of the cells in that extra row to green, and have the green format go out to the last column with data on it? Also, what if I needed to add an additional line below the the "green line"?

Troy
 
Upvote 0
This sounds like mission creep ;), any other requirements?
Also what is the last used column?
 
Upvote 0
Hey Fluff,

I'm am really trying to figure this stuff out on my own. I feel bad having to bother you :(..... I guess I should have given all of the information at once.

Requirements;

* Two blank lines with the bottom line being green. Green would go out to column "L"
* On the first blank line, I would like to sum column "F" and that would repeat on every grouping that has the two blank lines.

I'm sorry to keep bothering you with my problems:confused:

Troy
 
Upvote 0
How about
Code:
Sub AddRows()
   Dim i As Long, j As Long
   
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Cells(i, 1) <> Cells(i - 1, 1) Then
         Rows(i).Resize(2).Insert
         Cells(i + 1, 1).Resize(, 12).Interior.Color = 45678
         If j <> 0 Then Cells(j, 6).Formula = "=sum(" & Range("F" & i + 2).Resize(j - i - 2).Address & ")"
         j = i + 2
      End If
   Next i
End Sub
 
Upvote 0
OMG, that would have taken me months to figure out! One last challenge and I promise I will leave you alone.... In the very last grouping, I don't get the extra two lines with one of them being green. I also don't get the formula. What do I need to modify in the code to include the very last grouping?
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top