How can I change 49:47:16,20 to 49°47'16.20" in large data set?

pcvchriskmg

Board Regular
Joined
Feb 10, 2010
Messages
118
Hello,

I have a large list of latitude and longitude points, but they are not in the correct format. For example, they are in the format : 49:47:16,20 as opposed to 49°47'16.20" (Google maps can only read the latter).

I recorded a small little macro that replaces the first colon (:) with the degrees sign (°), the second colon (:) with the hours (') and the comma (,) with a period (.) I then added the minutes (") at the end, When I run it, however, it replaces the numbers with the original numbers in the cell that I had recorded the macro on.

I also experimented a little bit with "Find and Replace" but that didn't work either.

What's a simple way for me to change the format of all these cells so that I have the correct latitude/longitude format?

Thanks in advance,
Chris
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Assuming your data is in column A of sheet1, starting from row 2...

Code:
Sub Latitude()
Dim Last_Row As Long
Dim r As Range
Dim s As String

Application.ScreenUpdating = False

With Sheets("Sheet1")

    Last_Row = Range("A" & Rows.Count).End(xlUp).Row
    
    For Each r In Range(.Cells(2, 1), .Cells(Last_Row, 1))
        s = r.Value
        s = Replace(s, ":", "°", Count:=1)
        s = Replace(s, ":", "'")
        s = Replace(s, ",", ".")
        s = s & """"
        r = s
    
    Next r
    
End With

Application.ScreenUpdating = True

End Sub
 
Upvote 0
If this 49:47:16,20 is in cell A1, try a formula like this...

=TEXT(SUBSTITUTE(TRIM(A1),",",".")*1,"[h]°mm'ss.00")

Result:
49°47'16.20
 
Last edited:
Upvote 0
Assuming your data is in column A of sheet1, starting from row 2...

Code:
Sub Latitude()
Dim Last_Row As Long
Dim r As Range
Dim s As String

Application.ScreenUpdating = False

With Sheets("Sheet1")

    Last_Row = Range("A" & Rows.Count).End(xlUp).Row
    
    For Each r In Range(.Cells(2, 1), .Cells(Last_Row, 1))
        s = r.Value
        s = Replace(s, ":", "°", Count:=1)
        s = Replace(s, ":", "'")
        s = Replace(s, ",", ".")
        s = s & """"
        r = s
    
    Next r
    
End With

Application.ScreenUpdating = True

End Sub

Thank you!

This works great.

Chris
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top