
Originally Posted by
Crusaders43
Richard Buttrey,
Let me start off by thanking you!!!!
Wow, that was great....it worked perfectly...
I just have 3 questions....
First, if I wanted to add a column to everything with the same concept...in other words, in column "C" I had a category labeled 'wind' and it also had an increase rate column added to the increase rate table. Assuming the increment of both wind and mph occur at similar times, how would I add another column to this code?
Also, I've been playing with the code a bit and don't want to bunk it up. But how do I take off the 'mph' part of it?
Finally, what if I had numbers such as 745 instead of 7:45?
I have added another file that sums up these 3 questions into one example.
Please take a look.
I really do appreciate the help, I'm very grateful. Thanks again
Hi,
Use the modified code below.
Re the mph.
Because you had the 'mph' in the first occurrence, the original code needed to slice this text string with the LEFT() bit of code, and pick the characters ignoring the last 4 (i.e. the leading space and 'mph'). Now that you no longer have mph as a bit of text, this bit of code is not necessary.
Re the formatting.
Originally you were formatting the time numbers to look like a traditional presentation of time i.e. 7:45 and hence the code needed the bit about Format(....the lookup function, "hh : mm"). It's actually easier if you just have the raw numbers as per this second example since no special formatting is needed - hence I've left that bit out too.
Sub IncrementMPH()
Dim x As Integer, iIncrRate As Integer, iIncrWind As Integer, stSpeed As String, iSpeed As Integer, iWind As Integer, dTime As Double
x = Range(Range("DataTop"), Range("DataTop").End(xlDown)).Rows.Count
For x = 1 To Range(Range("DataTop"), Range("DataTop").End(xlDown)).Rows.Count
If Range("datatop").Offset(x - 1, 1) <> "" Then
iSpeed = Range("datatop").Offset(x - 1, 1)
iWind = Range("datatop").Offset(x - 1, 2)
Range("datalist").Offset(x - 1, 0) = Range("datatop").Offset(x - 1, 0)
Range("datalist").Offset(x - 1, 1) = Range("datatop").Offset(x - 1, 1)
Range("datalist").Offset(x - 1, 1) = iSpeed
Range("datalist").Offset(x - 1, 2) = iWind
Else
dTime = Range("datatop").Offset(x - 1, 0)
iIncrRate = Application.WorksheetFunction.VLookup(dTime, Range("Increase"), 2)
iIncrWind = Application.WorksheetFunction.VLookup(dTime, Range("Increase"), 3)
Range("datalist").Offset(x - 1, 0) = Range("datatop").Offset(x - 1, 0)
Range("datalist").Offset(x - 1, 1) = Range("datatop").Offset(x - 1, 1)
Range("datalist").Offset(x - 1, 1) = iSpeed + iIncrRate
Range("datalist").Offset(x - 1, 2) = iWind + iIncrWind
iSpeed = iSpeed + iIncrRate
iWind = iWind + iIncrWind
End If
Next x
End Sub
Regards
Bookmarks