Martin Perera
Board Regular
- Joined
- Jan 17, 2005
- Messages
- 147
Hi Guys
I am rather new to dealing with Macro's and VBA
I have a problem which I hope you could help me with.
I am building a balance sheet, with a set number of spaces for entrys. The aim is to set a macro or function sub whatever that fires when the last entry is entered. the macro will then insert a new row for the next entry.
I have managed to get the code to insert the required row by using a range("NewRow") reference, ie naming a cell in the spreadsheet. Unfortunetly it can only fire the once as the new row leaves the reference behind.
what I need is a way of promoting the named cell with the code so that EVERY time the user gets to the last row the macro fires
hope this is clear
probably going about this all wrong
Martin
I am rather new to dealing with Macro's and VBA
I have a problem which I hope you could help me with.
I am building a balance sheet, with a set number of spaces for entrys. The aim is to set a macro or function sub whatever that fires when the last entry is entered. the macro will then insert a new row for the next entry.
I have managed to get the code to insert the required row by using a range("NewRow") reference, ie naming a cell in the spreadsheet. Unfortunetly it can only fire the once as the new row leaves the reference behind.
what I need is a way of promoting the named cell with the code so that EVERY time the user gets to the last row the macro fires
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Intersect(Range("NewRow"), Target) Is Nothing Then Exit Sub 'if nowt there do nothing
'NewRow is the named cell, where once changed the new row needs to go
If IsEmpty(Range("NewRow")) Then Exit Sub 'on change insert row
Application.EnableEvents = False
Range("NewRow").Offset(rowOffset:=1, columnOffset:=0).Select
'offset because otherwise the data entered had a new row inserted above it
Selection.EntireRow.insert
Range("NewRow").Offset(rowOffset:=1, columnOffset:=0).Select
Application.EnableEvents = True
End Sub
hope this is clear
probably going about this all wrong
Martin