Note: The other languages of the website are Google-translated. Back to English
Log på  \/ 
x
or
x
Tilmeld  \/ 
x

or

Hvordan konverteres decimalgrader til grader minutter sekunder i Excel?

Nogle gange har du muligvis en liste over data vist som decimalgrader i et regneark, og nu skal du konvertere decimalgraderne til grader, minutter og sekunder, som vist som følgende skærmbilleder. Hvordan kan du få samtalen hurtigt i Excel?

Konverter decimalgrader til grader, minutter, sekunder med VBA

Konverter grader, minutter, sekunder til decimalgrader med VBA

Fanen Office Aktiver redigering og browsing med faner i Office, og gør dit arbejde meget lettere ...
Kutools til Excel løser de fleste af dine problemer og øger din produktivitet med 80%
  • Genbrug alt: Tilføj de mest anvendte eller komplekse formler, diagrammer og alt andet til dine favoritter, og genbrug dem hurtigt i fremtiden.
  • Mere end 20 tekstfunktioner: Uddrag nummer fra tekststreng; Uddrag eller fjern en del af teksterne; Konverter tal og valutaer til engelske ord.
  • Flet værktøjer: Flere arbejdsbøger og ark til én; Flet flere celler / rækker / kolonner uden at miste data; Flet duplikatrækker og sum.
  • Opdel værktøjer: Opdel data i flere ark baseret på værdi; Én projektmappe til flere Excel-, PDF- eller CSV-filer; En kolonne til flere kolonner.
  • Indsæt spring Skjulte / filtrerede rækker; Tæl og sum af baggrundsfarve; Send personaliserede e-mails til flere modtagere i bulk.
  • Superfilter: Opret avancerede filterskemaer og anvend dem på alle ark; Sort efter uge, dag, hyppighed og mere; filtre med fed, formler, kommentar ...
  • Mere end 300 kraftfulde funktioner; Arbejder med Office 2007-2019 og 365; Understøtter alle sprog Nem implementering i din virksomhed eller organisation.

pil blå højre boble Konverter decimalgrader til grader, minutter, sekunder med VBA


Følg nedenstående trin for at konvertere decimalgrader til grader, minutter og sekunder med VBA-kode.

1. Holde ALT og tryk på F11 på tastaturet for at åbne en Microsoft Visual Basic til anvendelse vindue.

2. klik indsatte > Moduler, og kopier VBA til modulet.

VBA: Konverter decimalgrad til grad, minutter og sekunder

Sub ConvertDegree()
'Update 20130815
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    num1 = Rng.Value
    num2 = (num1 - Int(num1)) * 60
    num3 = Format((num2 - Int(num2)) * 60, "00")
    Rng.Value = Int(num1) & "°" & Int(num2) & "'" & Int(num3) & "''"
Next
End Sub

3. klik Kør knappen eller tryk på F5 at køre VBA.

4. En dialog vises på skærmen, og du kan vælge de celler, du vil konvertere. Se skærmbillede:

5. klik OK, så konverteres de valgte data til grad, minutter og sekunder. Se skærmbillede:

Tip: Brug af ovenstående VBA-kode mister dine originale data, så du må hellere kopiere dataene, før du kører koden.


pil blå højre boble Konverter grader, minutter, sekunder til decimalgrader med VBA

Nogle gange vil du muligvis konvertere data i grader / minutter / sekunder formatering til decimalgrader, den følgende VBA-kode kan hjælpe dig med hurtigt at få det gjort.

1. Holde ALT-knappen, og tryk på F11 på tastaturet for at åbne et Microsoft Visual Basic til applikationsvindue.

2. klik indsatte > Moduler, og kopier VBA til modulet.

VBA: Konverter grad, minutter og sekunder til decimalgrad

Function ConvertDecimal(pInput As String) As Double
'Updateby20140227
Dim xDeg As Double
Dim xMin As Double
Dim xSec As Double
xDeg = Val(Left(pInput, InStr(1, pInput, "°") - 1))
xMin = Val(Mid(pInput, InStr(1, pInput, "°") + 2, _
             InStr(1, pInput, "'") - InStr(1, pInput, _
             "°") - 2)) / 60
xSec = Val(Mid(pInput, InStr(1, pInput, "'") + _
            2, Len(pInput) - InStr(1, pInput, "'") - 2)) _
            / 3600
ConvertDecimal = xDeg + xMin + xSec
End Function

3. Gem koden, og luk vinduet, vælg en tom celle, f.eks. Celle A1, indtast denne formel = ConvertDecimal ("10 ° 27 '36" "") ("10 ° 27 '36" "" står for den grad, du vil konvertere til decimalgrad, du kan ændre det efter behov), og klik derefter på Indtast knap. Se skærmbilleder:


Relative artikler

Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Jon · 11 months ago
    WRONG calculation results... 29°30'13" 34°55'4" ---> 29.00083333 34.08333333
  • To post as a guest, your comment is unpublished.
    ValdrichF · 2 years ago
    The code has a assumes there is a space after ° and '. Change the 2's to 1's in the code to solve it.
    Function ConvertDecimal(pInput As String) As Double
    'Updateby20140227
    Dim xDeg As Double
    Dim xMin As Double
    Dim xSec As Double
    xDeg = Val(Left(pInput, InStr(1, pInput, "°") - 1))
    xMin = Val(Mid(pInput, InStr(1, pInput, "°") + 1, _
    InStr(1, pInput, "'") - InStr(1, pInput, _
    "°") - 1)) / 60
    xSec = Val(Mid(pInput, InStr(1, pInput, "'") + _
    1, Len(pInput) - InStr(1, pInput, "'") - 1)) _
    / 3600
    ConvertDecimal = xDeg + xMin + xSec
    End Function
  • To post as a guest, your comment is unpublished.
    Sandeep · 3 years ago
    Works like a champ! Thanks for sharing!!!
    • To post as a guest, your comment is unpublished.
      Ritesh · 3 years ago
      Check your results. this code is wrong.
  • To post as a guest, your comment is unpublished.
    ahans · 3 years ago
    please
    i want you help and write a computer program on paper to convert decimal of degree to degree minute and second.
    317.5986740026
    from ahans.
    • To post as a guest, your comment is unpublished.
      Amjid afridi · 3 years ago
      step 1, Multiply numbers after decimal with 60 (0.5986740026*60)minutes=35.92044015 mean 35 mints
      spet 2, multiply the decimal after minute ie 0.9204401*60=55.2264
      so 317 degree 35 minuts 55 sec
  • To post as a guest, your comment is unpublished.
    Corny · 3 years ago
    Not sure whats wrong with the code in the post from Ernie, but this is what I use to convert decimal degrees to DMS degrees in the spread sheet without using VB. The reference to the cell E33 is the cell containing the decimal degrees value.

    =CONCAT(FIXED(INT(B32), 0) , "°", FIXED(((B32 - INT(B32)) * 60), 0), "'", FIXED(((B32 - INT(B32) - INT(B32 - INT(B32))) * 3600), 0 ,TRUE), """)

    Good luck.
    • To post as a guest, your comment is unpublished.
      RAMON GOMEZ · 3 years ago
      HI CORNY, NOT WORK FOR ME, EXCEL DO NOT ACCEPT THE FUNCTION..... WHATS WRONG? CAN YOU HELP ME?
  • To post as a guest, your comment is unpublished.
    Ernie · 4 years ago
    Hello,
    I used the scrip to convert decimal to DMS however the code is wrong somewhere as it turned out 37.856908,-120.912469 to 37D 51M 25S, -121D 5M 15S
    This is way off....

    Anyone have a fix for this?
  • To post as a guest, your comment is unpublished.
    Ryan Smith · 4 years ago
    works great but how would i adapt the code to get more numbers for seconds?
  • To post as a guest, your comment is unpublished.
    Gregory · 4 years ago
    I want to plot the positions on a map and we not worry about N, S, E or W. I'm sure these could be added in with "if" statements.
    I have just used a very simple line of functions within the Excel spreadsheet.
    I want to go from Degrees (Decimal) to Degrees, Seconds (Decimal) Changing the negative values to positives as I know which hemispheres I am in. For me, cell E4 contained the target Lat or Long (Decimal).
    This is a bit easier than putting in some VBA code and can be enlarged to do DD,MM,SS

    =CONCATENATE(TRUNC(ABS(E4)),"°",FIXED((ABS(E4)-TRUNC(ABS(E4)))*60,2),"'")
  • To post as a guest, your comment is unpublished.
    Mou · 5 years ago
    Found this code very helpful. Great stuff!
  • To post as a guest, your comment is unpublished.
    Mort Wakeland · 5 years ago
    The most important thing to realize is that you cannot simply use superscript and small letter o for the degree symbol - this may be obvious to some, but not to me. I tried the superscript letter o and it did not work, I deleted the superscript letter o, and used Alt 0176 for the actual degree symbol and it worked!! I am confused as to why after the seconds there are extra sets of double quotes?
    36""") whereas in the subsequent comment if one simply uses =ConvertDecimal(A1) only a single set of quotes are used for seconds. Odd we can use single and double quotes and the thing works for minutes and seconds but superscript letter o does not?
    To check 27/60 = .45 smf 36/3600 = .01 add the two = .46 and add that to the degrees = 10.46 degrees. Hope this helps others? Mort
  • To post as a guest, your comment is unpublished.
    Levi · 6 years ago
    Really helpful.
    Thank you.
  • To post as a guest, your comment is unpublished.
    Rajansinh Zala · 6 years ago
    there is some error in code i tried to convert 26°10'55.416" using this code which results as 26.00139 which should be 26.18206 (Calculated & Verified.. please let me know if anyone knows the reason.
    • To post as a guest, your comment is unpublished.
      Gunnar · 6 years ago
      [quote name="Rajansinh Zala"]there is some error in code i tried to convert 26°10'55.416" using this code which results as 26.00139 which should be 26.18206 (Calculated & Verified.. please let me know if anyone knows the reason.[/quote]

      It seems the code expects a space after the ° and ' symbols.
      26° 10' 55.416" gives the correct answer.
      You can enter your input in a cell (eg A1) and get the result in another cell by using the formula =ConvertDecimal(A1). This is convenient if you have a many numbers to be converted.