ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rusty at excel, could use a hand with a macro (https://www.excelbanter.com/excel-programming/455387-rusty-excel-could-use-hand-macro.html)

Megz

Rusty at excel, could use a hand with a macro
 
I am making a program to show work done on a home, and have a pile of old receipts to input.
I have pulled down in first column dates involved, but end up copy/paste any date that has more than one receipt, so would like a macro that I can click on a date and have it insert a line underneath with same date.

ExcelBanter AI

Answer: Rusty at excel, could use a hand with a macro
 
Here's the formatted BBcode:

Step-by-step guide on how to create a macro that will insert a new row with the same date when you click on a cell with a date in it:
  1. Open your Excel workbook and go to the worksheet where you want to add the macro.
  2. Press
    Code:

    Alt + F11
    to open the Visual Basic Editor.
  3. In the Visual Basic Editor, go to Insert Module to create a new module.
  4. In the new module, paste the following code:

    Formula:

    Sub InsertRowWithDate()

        
    Dim selectedDate As Date
        Dim lastRow 
    As Long
        
        selectedDate 
    ActiveCell.Value
        lastRow 
    Cells(Rows.Count1).End(xlUp).Row
        
        
    For lastRow To 2 Step -1
            
    If Cells(i1).Value selectedDate Then
                Rows
    (1).Insert Shift:=xlDown
                Cells
    (11).Value selectedDate
            End 
    If
        
    Next i
    End Sub 

  5. Save the module and close the Visual Basic Editor.
  6. Go back to your worksheet and select the cell with the date you want to insert a new row for.
  7. Click on the Developer tab in the ribbon (if you don't see it, go to File Options Customize Ribbon and check the Developer box).
  8. Click on the "InsertRowWithDate" button in the Controls group.
  9. A new row with the same date as the selected cell should now be inserted below it.

That's it! You can now use this macro to quickly insert new rows with the same date as any cell you select.

Megz

This I tried....no workie
 
Sub AddLine()
'
' AddLine Macro
' Adds a line with same date under chosen line
'
' Keyboard Shortcut: Ctrl+l
'
Sub Paste_OneRow()

'Copy and Paste Row
Range("1:1").Copy Range("2:2")


'Cut and Paste Row
Range("1:1").Cut Range("2:2")

End Sub


All times are GMT +1. The time now is 08:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com