vendredi 20 février 2015

VBA is saving variable when using lastRow function

My problem is the following. I am using some VBA to format some data I transfer from a Reflection terminal to an Excel worksheet.


Fx my first export would be on our customers in Region X with Product Z. Then it creates new workbook and places the data in the correct columns etc. lets say this export is 20 rows. So far everything is fiiiiiiiiiine :)!


Then afterwards I want to make another export, this time on Region Y with product Z. Then it creates new workbook Again, but this time the data is over 100 rows.


Then the formatting is only correct in the first 20 rows.... and this is what I find weird.


Hope someone can help me with this :)


Best Regards Palle



With ws.Range("a1:f1")
.HorizontalAlignment = xlCenter
.Font.Italic = True
.Font.Bold = True
.EntireColumn.ColumnWidth = 15
.AutoFilter
End With

With ws.Range("a2:f" & antalRaekker)
.HorizontalAlignment = xlCenter
End With





Function LastRow() As Long
Dim ix As Long
ix = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
LastRow = ix

End Function





Aucun commentaire:

Enregistrer un commentaire