Writing to range??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

OK, this should be simple.... I'm trying to combine the cotents of several ranges onto a new workbook. I can get the needed range, and I can add a new workbook, but everytime I try to add the data into the cell, I get an error that says "System or application defined error"

Here's the relevant code

Private Sub rangeData(StartCell As String, EndCell As String

Dim objRange As Rang
Dim I, N As Intege

' ************************************************************
' This sub steps through a range and pulls all the data from i
' ************************************************************

Set objRange = objWB.Worksheets(2).Range(StartCell, EndCell

For I = 0 To objRange.Rows.Coun

For N = 1 To

If Trim(objRange(I, N)) <> "" The

objNewBook.Worksheets(1).Range(Cells(lngLastRow, N)) = objRange(I, N) ' This line has the erro

End I

Nex

lngLastRow = lngLastRow +

Nex

Set objRange = Nothin

End Su

I know that objRange(I, N) has the value I want, but for some reason I can't add it into objNewBook. Here's the code that created the new book

Application.SheetsInNewWorkbook =
Set objNewBook = objXL.Workbooks.Ad
lngLastRow =
Application.SheetsInNewWorkbook =

objNewBook is defined with project level scope

Help!!
 
objRange(I, N)

notation is 1's based.

if objRange starts in row 1, then objRange(0,1) would be row zero which
doesn't exist and would raise an error.

In otherwords Range("A1").Offset(0,0) refers to A1, but Range("B2")(0,0)
refers to A1.

demo'd from the immediate window:
? Range("B2")(0,0).address
$A$1


Just one possibility
--
Regards,
Tom Ogilvy

MDW said:
OK, this should be simple.... I'm trying to combine the cotents of
several ranges onto a new workbook. I can get the needed range, and I can
add a new workbook, but everytime I try to add the data into the cell, I get
an error that says "System or application defined error".
Here's the relevant code:

Private Sub rangeData(StartCell As String, EndCell As String)

Dim objRange As Range
Dim I, N As Integer

' *************************************************************
' This sub steps through a range and pulls all the data from it
' *************************************************************

Set objRange = objWB.Worksheets(2).Range(StartCell, EndCell)

For I = 0 To objRange.Rows.Count

For N = 1 To 2

If Trim(objRange(I, N)) <> "" Then

objNewBook.Worksheets(1).Range(Cells(lngLastRow, N)) =
objRange(I, N) ' This line has the error
End If

Next

lngLastRow = lngLastRow + 1

Next

Set objRange = Nothing

End Sub

I know that objRange(I, N) has the value I want, but for some reason I
can't add it into objNewBook. Here's the code that created the new book.
 
Back
Top