Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Norm,
If you run this a lot, reading the range into an array and working within memory is much faster than so many individual cell references. 'In Norman's macro, add Dim ary As Variant, x As Integer 'change Set Rng = SH.Range("N17:A" & iLastRow) to Set Rng = SH.Range("N17:B" & iLastRow) to make a 2 column array 'replace the "For Each rCell In Rng.Cells" loop with ' column 1 holds the directions, column 2 the degrees ' read columns 1, 2 into the array ary = Rng For x = 1 To UBound(ary, 1) res = Application.Match(ary(x, 1), ArrText, 0) If Not IsError(res) Then ' set column 2 ary(x, 2) = ArrDeg(res - 1) End If Next x ' put the array to columns 1, 2 Rng = ary Carl. On Apr 7, 10:52 pm, Norm Shea wrote: Thank you all for the responses and suggestions. I ended up using Norman's script because that was what I was most familiar with. It worked great. I really appreciate it. One of these days I should to take a VB class. Thanks again, Norm "Norman Jones" wrote: Hi Norm, Alternatively, try: '<<============= Public Sub Tester() Dim WB As Workbook Dim SH As Worksheet Dim Rng As Range Dim rCell As Range Dim iLastRow As Long Dim ArrText As Variant Dim ArrDeg As Variant Dim CalcMode As Long Dim res As Variant Set WB = Workbooks("MyBook.xls") '<<=== CHANGE Set SH = WB.Sheets("Sheet1") '<<=== CHANGE iLastRow = SH.Cells(Rows.Count, "A").End(xlUp).Row Set Rng = SH.Range("N17:A" & iLastRow) ' ArrText = VBA.Array("N", "NNE", "NE", "ENE", "E", "ESE", _ "SE", "SSE", "S", "SSW", "SW", "WSW", _ "W", "WNW", "NW", "NNW") ArrDeg = VBA.Array(0, 23, 45, 68, 90, 113, 135, 158, 180, _ 203, 225, 248, 270, 293, 315, 338) On Error GoTo XIT With Application CalcMode = .Calculation .Calculation = xlCalculationManual .ScreenUpdating = False End With For Each rCell In Rng.Cells With rCell res = Application.Match(.Value, ArrText, 0) If Not IsError(res) Then .Value = ArrDeg(res - 1) End If End With Next rCell XIT: With Application .Calculation = CalcMode .ScreenUpdating = True End With End Sub '<<============= --- Regards, Norman "Norm Shea" wrote in message ... My macro skills are not great so I'm hoping someone can help me. I'm trying to come up with a macro that will convert Wind Direction from text to degrees in a number of different files. The data typically starts at N17 and extends down to roughly N26000. Here is the format I need to create. N 0 NNE 23 NE 45 ENE 68 E 90 ESE 113 SE 135 SSE 158 S 180 SSW 203 SW 225 WSW 248 W 270 WNW 293 NW 315 NNW 338 Thanks for any assistance anyone can provide. *** Sent via Developersdexhttp://www.developersdex.com*** |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Average Wind Direction | Excel Worksheet Functions | |||
Average wind direction | Excel Discussion (Misc queries) | |||
wind direction | Excel Discussion (Misc queries) | |||
Convert wind direction to degrees | Excel Programming | |||
Set cell text direction (degrees property?) via visual basic | Excel Programming |