• I get an error 2015 at "sourceRange.Cells(1, i);" without offset, in the code below


    Code
    For i = 1 To WorksheetFunction.CountA(Sheets("To Be Logged").Range("1:1")) + 1
            Print #current, "   <" & sourceRange.Cells(1, i).Offset(1, 0); ">" & sourceRange.Cells(1, i); "</" & sourceRange.Cells(1, i).Offset(1, 0); ">"
        Next i


    and im unsure why.


    when i replace "i" with "1" it works, but not how i want it to, and when I change it to "2" it doesnt.


    the method of selecting a cell works for all the other references just not the middle one, plz help.

  • Re: Error 2015


    sure, this is how it ended up:


    Code
    For i = 1 To WorksheetFunction.CountA(Sheets("To Be Logged").Range("1:1")) + 1
            Label = sourceRange.Cells(1, i).Offset(1, 0)
            Reading = sourceRange.Cells(1, i).Text
            If Reading = "" Then Reading = "Error Reading"
            Print #current, "<Data_Log>"
            Print #current, "   <Label>" & Label; "</Label>"
            Print #current, "       <Reading>" & Reading; "</Reading>"
            Print #current, "</Data_Log>"
        Next i


    basically all i did was add ".Text" to then end of the problem reference

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!