Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Out of range?

Status
Not open for further replies.

Guvnor

Technical User
Mar 26, 2002
12
GB
I keep on getting the error out of range. Can somone please tell me what needs to be changed in order to make this code work?

Sub InsertBaldata3()
Dim myRowCount As Integer
Dim myRng As Range

Set myRng = Sheets("insert balance data (2)").Range("1:1")

myRowCount = Application.CountA(myRng) - 1

With Sheets("company balance sheet(2)")
.Cells(myRowCount + 5, 5).Value = myRng.Range("b8").Value
.Cells(myRowCount + 6, 5).Value = myRng.Range("b9").Value
.Cells(myRowCount + 8, 5).Value = myRng.Range("b11").Value
.Cells(myRowCount + 9, 5).Value = myRng.Range("b12").Value
.Cells(myRowCount + 10, 5).Value = myRng.Range("b13").Value
.Cells(myRowCount + 11, 5).Value = myRng.Range("b14").Value
.Cells(myRowCount + 13, 5).Value = myRng.Range("b16").Value
.Cells(myRowCount + 14, 5).Value = myRng.Range("b17").Value
.Cells(myRowCount + 15, 5).Value = myRng.Range("b18").Value


End With

End Sub
 

Did you change the sheet name? Coincidentally, I dropped your code into a new workbook and forgot to change the sheet name of "insert balance data(2)" and got the same error. Then I changed the name to "sheet1" which is a valid worksheet in my workbook and it worked without error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top