samedi 28 mars 2015

VBA Excel - Write results from variable loop into sheet

I am trying to write the months from today until September into my excel sheet using a macro. Here is part of the code I have a problem with:



Dim months(1 To 12) As String

For i = m To 9
months(i) = i
Cells(31 + i, 6) = MonthName(months(i))
Next i


The code basically works, but the problem is that the first cell in the excel spreadsheet varies with the value of i. For example, if today is March, the first cell will be (34,6), but if it is April it will be (35,6). Can anybody give me a hint how to "fix" the first cell?


Thank you very much, Stefan


Aucun commentaire:

Enregistrer un commentaire