Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

asked on

Add data to the end of a range

I multiple range that, thorugh forms and VBA, i need to add data to.  The procedure does add a blank row (shitfs down one line for the insert), but when I use the Cells function,it throws an error.  I do not know why.  I get run time error of 424, Object required.
Private Sub InsertData()
'First need to insert a row below range, then add new data and
'finally call the range reset procedure
intRowEnd = fntRangeStartEndsRows("End", "ss_WAL") + 1

ThisWorkbook.Worksheets("Datasource").Range("L" & intRowEnd & ":" & "P" & intRowEnd).Select
ThisWorkbook.Worksheets("Datasource").Range("L" & intRowEnd & ":" & "P" & intRowEnd).Select
Selection.Insert Shift:=xlDown

With ThisWorkbook.Worksheets("Datasource").Range("ss_WAL").Rows.Count + 1
                    .Cells(0, 1).Value = Me.txtWAL.Value
                    .Cells(1, 2).Value = Me.txtLookupClient.Value
                    .Cells(2, 3).Value = Me.txtLookupLehman.Value
                    .Cells(3, 4).Value = Me.txtColumnNumber.Value
                    .cell(3, 5).Value = Me.txtRangeName.Value
End With
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sandra Smith

ASKER

Fixed that, but still get the error.  I did change the first value of the cells all to 0 as the data needs to go into the same row.
actually, I have solved it.  attached is the code and it works.
Private Sub InsertData()
Dim intCount As Integer
'First need to insert a row below range, then add new data and
'finally call the range reset procedure
intRowEnd = fntRangeStartEndsRows("End", "ss_WAL") + 1

ThisWorkbook.Worksheets("Datasource").Range("L" & intRowEnd & ":" & "P" & intRowEnd).Select
Selection.Insert Shift:=xlDown
intCount = ThisWorkbook.Worksheets("Datasource").Range("ss_WAL").Rows.Count + 1

With ThisWorkbook.Worksheets("Datasource").Range("ss_WAL")
                    .Cells(intCount, 1).Value = Me.txtWAL.Value
                    .Cells(intCount, 2).Value = Me.txtLookupClient.Value
                    .Cells(intCount, 3).Value = Me.txtLookupLehman.Value
                    .Cells(intCount, 4).Value = Me.txtColumnNumber.Value
                    .Cells(intCount, 5).Value = Me.txtRangeName.Value
End With
End Sub

Open in new window

This was the first step toward success so I did need to change that.
thx...Glad you were able to work through it :)