how do i create a macro to insert a new row after a date change occurs in a column
how do i create a macro to insert a new row after a date change occurs in a column
i know this creates a new record:
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveWindow.SmallScroll Down:=12
but i want it to do it when the date changes in the column B
Hi nana15nuna
1. Use code tags around any code you post
2. Research Change Event Code...depending on how the date changes, Change Event could well be part of your solution.
3. Research Target Cells or Target Column, it could also be part of your solution (depending on how the date changes).
4. Post a sample file of what you're trying to accomplish (before and after)...perhaps one of us can help.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please mark your Thread as SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
this code worked best for me:
Sub Insert_row()
Dim Number_of_rows As Long
Number_of_rows = ActiveSheet.UsedRange.Rows.Count
Worksheets("Dec2011-130").Range("B52").Select
Do Until Selection.Row = Number_of_rows + 1
If Selection.Value <> Selection.Offset(-1, 0).Value Then
Selection.EntireRow.Insert
Number_of_rows = Number_of_rows + 1
Selection.Offset(2, 0).Select
Else
Selection.Offset(1, 0).Select
End If
Loop
End Sub
This is the new code im trying to use for yet another step in my project:
Sub checkthatstuff()
Dim CheckRange As Range
Dim LastRow As Long
LastRow = Range("D" & Rows.Count).End(xlUp).Row
CheckRange = Range("D538" & ":D62165")
For Each Cell In CheckRange
If Cell.Value = "" Then
ActiveCell.FormulaR1C1 = "=SUM(R[-11]C:R[-1]C)"
Range("D62166").Select
End If
End Sub
Basically i have a column with values and consecutive cells in the column make up a range of values i want to sum up at the blank cell under the range:
Store Date Hour In Out Trans Sales Hours CR %
3 20110813 10 32 32 5 6.1 15.63%
3 20110813 11 99 78 11 7.17 11.11%
3 20110813 12 106 108 15 7.03 14.15%
3 20110813 13 103 97 15 7.45 14.56%
3 20110813 14 124 129 21 7.17 16.94%
3 20110813 15 122 111 17 6.92 13.93%
3 20110813 16 98 121 7 5.3 7.14%
3 20110813 17 71 73 11 5.32 15.49%
3 20110813 18 57 61 2 4.05 3.51%
3 20110813 19 44 43 5 4 11.36%
3 20110813 20 26 27 0 3.57 0.00%
882 109
Hi nana15nuna
You gotta use code tags around posted code...this is NOT optional...it's the Forum Rule...do it or don't expect further help.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks