Greetings,
The following code fills in date and times from starttime to stoptime (entered into cells B7 and B8 respectively) in column A. It also enters a direction in column E (in degrees), if an offset direction (entered into cell B6), which is added or subtracted from data in column D, is not zero.
Sub Add_Date()
Const incr = (1 / 144)
stTime = Range("B7").Value
endtime = Range("B8").Value + incr
Offset = Range("B6").Value
newTime = stTime
firstCell = Range("A13").Select
Do While newTime <= endtime
Application.ActiveCell = newTime
If Offset <> 0 Then
ActiveCell.Offset([0], [4]).Select
direction = ActiveCell.Offset([0], [-1]).Value
If direction < 180 Then
Application.ActiveCell = direction + Offset
Else: Application.ActiveCell = direction - Offset
End If
ActiveCell.Offset([0], [-4]).Select
End If
ActiveCell.Offset([1], [0]).Select
newTime = newTime + incr
Loop
End Sub
My question I guess comes in two parts:
First, if a start and stop time are given which contain fewer days than the original and the macro is run, the dates will fill in, but leave the remaining dates from previously showing. Is there any way to program the macro to clear any remaining cells in columns A and E?
Second, the macro takes a considerable amount of time to run with only two months worth of data. I may need to have it run through six months or more worth of times, so can the code be improved to increase speed? I am fairly new with the language and am not sure of syntax which would run more efficiently.
Thanks for your help!
The following code fills in date and times from starttime to stoptime (entered into cells B7 and B8 respectively) in column A. It also enters a direction in column E (in degrees), if an offset direction (entered into cell B6), which is added or subtracted from data in column D, is not zero.
Sub Add_Date()
Const incr = (1 / 144)
stTime = Range("B7").Value
endtime = Range("B8").Value + incr
Offset = Range("B6").Value
newTime = stTime
firstCell = Range("A13").Select
Do While newTime <= endtime
Application.ActiveCell = newTime
If Offset <> 0 Then
ActiveCell.Offset([0], [4]).Select
direction = ActiveCell.Offset([0], [-1]).Value
If direction < 180 Then
Application.ActiveCell = direction + Offset
Else: Application.ActiveCell = direction - Offset
End If
ActiveCell.Offset([0], [-4]).Select
End If
ActiveCell.Offset([1], [0]).Select
newTime = newTime + incr
Loop
End Sub
My question I guess comes in two parts:
First, if a start and stop time are given which contain fewer days than the original and the macro is run, the dates will fill in, but leave the remaining dates from previously showing. Is there any way to program the macro to clear any remaining cells in columns A and E?
Second, the macro takes a considerable amount of time to run with only two months worth of data. I may need to have it run through six months or more worth of times, so can the code be improved to increase speed? I am fairly new with the language and am not sure of syntax which would run more efficiently.
Thanks for your help!