LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Macro converting Wind Direction from text to degrees

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Average Wind Direction rexmorgan Excel Worksheet Functions 3 October 18th 05 04:30 AM
Average wind direction Phil Excel Discussion (Misc queries) 12 July 26th 05 12:02 PM
wind direction TC Excel Discussion (Misc queries) 3 July 14th 05 06:23 PM
Convert wind direction to degrees Larry[_16_] Excel Programming 5 March 17th 05 09:54 AM
Set cell text direction (degrees property?) via visual basic James[_24_] Excel Programming 2 June 23rd 04 01:03 PM


All times are GMT +1. The time now is 03:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"