Här är exempel på kod som fungerar i Excelboken men så fort jag lägger den i den personliga makroboken så ser allt bra ut tills man kommer till raden: For inputArticleRow = 3 To Blad1.Cells(Rows.count, "a").End(xlUp).Row 'start input at third row and read to last row that contains anything
Här hittas ingen data utan man hamnar i slutet av koden och makrot avslutas.
Någon som vet vad som är fel?
' reads from active sheet and creates a new sheet with formated data
Sub FormatPrediction()
'indexes
Dim inputArticleRow As Integer
Dim inputPredictionColumn As Integer
Dim outputArticleRow As Integer
'sheets
Dim outputSheet As Worksheet
Dim inputSheet As Worksheet
Set inputSheet = ActiveSheet
Set outputSheet = Sheets.Add
' do the formating
outputArticleRow = 1 ' start output at first row
For inputArticleRow = 3 To Blad1.Cells(Rows.count, "a").End(xlUp).Row 'start input at third row and read to last row that contains anything
For inputPredictionColumn = 2 To 6 ' read columns 2 to 6
outputSheet.Cells(outputArticleRow, 1).Value = inputSheet.Cells(inputArticleRow, 1).Value
outputSheet.Cells(outputArticleRow, 2).Value = Format(DateAdd("m", inputPredictionColumn - 1, Date), "YYYYMM") 'next month from current date as first prediction
outputSheet.Cells(outputArticleRow, 3).Value = inputSheet.Cells(inputArticleRow, inputPredictionColumn).Value
outputArticleRow = outputArticleRow + 1 ' adjust index for output
Next
Next
End Sub