RoyLittle0
11-05-2016, 01:57 AM
Hi, I am quite new to VBA and coding so please bear with me on this one.
I am using the following code to insert a row of data in an Excel sheet (Sheet 1 RAMS) from another sheet in the same workbook (Sheet 2 Risks), this copy is based on a Selection box in (Sheet 2 Risks), all works as it should and the data is populated into (Sheet 1 RAMS) in the next available empty cell in Column A – All good so far.
The (Sheet 1 RAMS) is a user form and will contain other data as well as the data being inserted from (Sheet 2 Risks) which is a master database, I have approximately 60 entries in (Sheet 2 Risks) and I am using the range B:H to copy over.
As (Sheet 1 RAMS) is a user form it will have data and formatting to it, it will not be a blank form, it will have an area to insert the data, preferably one row and then adding the data will also insert a second line and move everything below it down a row.
So, I have data in rows A1:A20 and A22:A120, can I insert the line of data into A21 and then insert a blank line A21, which moves A22:A120 down to A23:A121
When the Selection box is selected it inserts the contents into (Sheet 1 RAMS) but if it is subsequently de-selected it will remove it, delete it from (Sheet 1 RAMS)
I have tried a few different things like Rows("1:21") Range("1:21") but get an error or simply doesn’t work, so I am at a bit of a loss at the moment.
Sub CheckboxClicked()
Dim cel As Range, dest As Range, rw As Range, targ As Range
Set cel = ActiveSheet.Shapes(Application.Caller).TopLeftCell
Set rw = Intersect(cel.EntireRow, Range("B:H")) 'This is the number of columns to be coppied over to the RAMs work sheet
'This is the destination and offset based on cell A1
With Worksheets("RAMS")
Set dest = .Columns("A").Find(Application.Caller)
If dest Is Nothing Then
If cel.Value = True Then
Set dest = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
dest.Offset(0, 1).Resize(1, rw.Columns.Count).Value = rw.Value
'dest.Offset(0, rw.Columns.Count + 1).Value = Now 'Adds the date and time that the RAMS were added (Commented out)
dest.Value = Application.Caller
End If
Else
If cel.Value = False Then dest.EntireRow.Delete
End If
End With
End Sub
I am using the following code to insert a row of data in an Excel sheet (Sheet 1 RAMS) from another sheet in the same workbook (Sheet 2 Risks), this copy is based on a Selection box in (Sheet 2 Risks), all works as it should and the data is populated into (Sheet 1 RAMS) in the next available empty cell in Column A – All good so far.
The (Sheet 1 RAMS) is a user form and will contain other data as well as the data being inserted from (Sheet 2 Risks) which is a master database, I have approximately 60 entries in (Sheet 2 Risks) and I am using the range B:H to copy over.
As (Sheet 1 RAMS) is a user form it will have data and formatting to it, it will not be a blank form, it will have an area to insert the data, preferably one row and then adding the data will also insert a second line and move everything below it down a row.
So, I have data in rows A1:A20 and A22:A120, can I insert the line of data into A21 and then insert a blank line A21, which moves A22:A120 down to A23:A121
When the Selection box is selected it inserts the contents into (Sheet 1 RAMS) but if it is subsequently de-selected it will remove it, delete it from (Sheet 1 RAMS)
I have tried a few different things like Rows("1:21") Range("1:21") but get an error or simply doesn’t work, so I am at a bit of a loss at the moment.
Sub CheckboxClicked()
Dim cel As Range, dest As Range, rw As Range, targ As Range
Set cel = ActiveSheet.Shapes(Application.Caller).TopLeftCell
Set rw = Intersect(cel.EntireRow, Range("B:H")) 'This is the number of columns to be coppied over to the RAMs work sheet
'This is the destination and offset based on cell A1
With Worksheets("RAMS")
Set dest = .Columns("A").Find(Application.Caller)
If dest Is Nothing Then
If cel.Value = True Then
Set dest = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
dest.Offset(0, 1).Resize(1, rw.Columns.Count).Value = rw.Value
'dest.Offset(0, rw.Columns.Count + 1).Value = Now 'Adds the date and time that the RAMS were added (Commented out)
dest.Value = Application.Caller
End If
Else
If cel.Value = False Then dest.EntireRow.Delete
End If
End With
End Sub