mercredi 25 février 2015

Beginner in VB and having issues writing a Excell Macro

Been working on a VB Macro that takes vehicle service and MOT dates from a data entry page inserts it into a new line on idifernt sheetand caluclates future service dates on a set interval time I have entered. This all works fine its just the next part I am having trouble with. I then heed to take these dates and add them into a shedule.


I have tryed setting up nested do while and if loops but i can seam to get it working. Ive made an simplified example of what I am trying to do (link below).


Red is the manualy entered data. Yello is the 1st macro product with the new line containing copyed dates with orange calculated future dates. Green is the New line inserted (where i have got to) but I need the symbles insered into that new row.


http://ift.tt/1AriyfQ (Sorry for the imgur link. Site wont let me post it direct)


I have only been doing VB for a few months and am self taught so I dont even know if im on the right track. This is the basic code have have for entering the service dates into the shedule from the database.



x = 1
y = x + 1
z = 16
'my data starts in C6R16 and I have 5 dates (hence to 21)
Do While z < 21
'Have a shedule for the whole year so 53.
Do While x < 53
'If functions to locate which week the event is located
If Worksheets("Dates Input").Cells(6, z).Value > Worksheets("Maintenance Shedule").Cells(3, x) Then
If Worksheets("Dates Input").Cells(6, z).Value < Worksheets("Maintenance Shedule").Cells(3, y) Then
'Quick location of the lowest empy cell. The others will be full of data from prevous entries.
Range("F9:F10").Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop
'Move my active cell to the correct place
ActiveCell.Offset(-1, (3 + x)).Select
ActiveCell = "/"
Else
End If
'Move to the next set of dates in shedule
x = x + 1
Loop
'move to next service date
z = z + 1
Loop


I dont know if this is even close to correct but I have made a few macros, granted more simple than this and they seam to be ok. On top of this, I need to add (I assume) an IF to include to combine if there is an MOT (M) and service (/) in the same week so one dose not deleat the other.


Any pointers and help would be greatly apreciated. Have spent a week trying to get around this and am really lost.


Mike :)


Aucun commentaire:

Enregistrer un commentaire