Cryptocurrency Accounting in Excel by konstantint

View this thread on steempeak.com
· @konstantint · (edited)
$1.36
Cryptocurrency Accounting in Excel
No matter how many [specialized accounting tools](https://en.wikipedia.org/wiki/Comparison_of_accounting_software) there may exist nowadays, Microsoft Excel is still one of the best choices for keeping track of personal finances. It is easy to start with, incredibly flexible, and scales well to most accounting tasks a layperson might encounter in practice.

If you want to include cryptocurrencies to an Excel spreadsheet of your assets, you might discover a slight inconvenience - the prices of cryptocurrencies float like crazy all the time and updating them manually is a pain.

Fortunately, Excel makes it possible to add a custom function which will conveniently query the current exchange rates for you. Let me show you how to do it:

1. Go to *Developer ⇒ Visual Basic* in the Ribbon menu (or simply press **Alt+F11**).
<center>![ribbon.png](https://steemitimages.com/DQmY8SEQixrGpxE6mRE6XiDxdr64Uq126P2zvitSti3DMZd/image.png)</center>

2. The *Visual Basic for Applications* window will open. Right-click the "VBAProject", corresponding to your workbook, and choose *Insert ⇒ Module*:
<center>![module.png](https://steemitimages.com/DQmVU7LrbbA6y8zhBFuqcx8eKUCVGUZXneJhyDzU5GNBrap/image.png)</center>

3. Paste the following code into the newly opened module window:
    ```
    Public Function HttpGet(ByVal requestUrl As String) As String
        Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
        With http
            .Open "GET", requestUrl, True
            .Send ""
            .WaitForResponse
            HttpGet = .ResponseText
        End With
    End Function

    Public Function GetCryptoCurrencyPrice(ByVal name As String, Optional ByVal baseCurrency As String = "EUR", Optional ByVal cacheBuster As Object) As Double
        GetCryptoCurrencyPrice = -1#
        json = HttpGet("https://api.coinmarketcap.com/v1/ticker/" & name & "/?convert=" & baseCurrency)
        
        For Each Line In Split(json)
            If found Then
                GetCryptoCurrencyPrice = CDbl(Mid(Line, 2, Len(Line) - 3))
                Exit Function
            End If
            If Line = """price_" & LCase(baseCurrency) & """:" Then
                found = True
            End If
        Next
    End Function
    ```
    &nbsp;
4.  Close the *Visual Basic for Application* window (or press **Alt+F11**) to go back to the spreadsheet. 

You are now free to use the `GetCryptoCurrencyPrice` function in the worksheet, just like any other Excel function. It will query the current prices from the [coinmarketcap.com](https://coinmarketcap.com/) website. The function has three parameters:
 - The name of the cryptocurrency, as it is named on Coinmarketcap (e.g. Bitcoin is called `bitcoin`, Steem is `steem` and SBD is `steem-dollars`).
 - The name of the target currency ("EUR", "USD", "AUD", "RUB", "NOK", "SEK", etc). "BTC" also works.
 - An optional pointer to a cell, changing the value of which will trigger a new query.

Here is how you would use it within a typical table:
<center>![](https://steemitimages.com/DQmR8bh7hV4hXwthb71XjnXCPTs3Mv8imUBkvi3vWNuSMuY/image.png)</center>

Note that the empty cell `A1` is referenced in the formula so that we could trigger a query to refresh the price by simply modifying `A1` (just writing a random character and removing it, for example).

Now drag the newly created formula to fill the whole column, add the computations for the total value and voilà - your very own cryptocurrency portfolio management tool. Similar to, say, [Cryptofolio](http://cryptofolio.info/), but more flexible and not limited to cryptocurrencies (on the downside - it is not web-based and won't work on your phone).

<center>![](https://steemitimages.com/DQmTXsnNxj2Mo4VDbceEHwUoffu3HUVniq5zzbYm95t1ZZX/image.png)</center>
👍  , , , , , , , , , , , , , , , , , , , ,
properties (23)
post_id11,420,766
authorkonstantint
permlinkcryptocurrency-accounting-in-excel
categoryhowto
json_metadata"{"app": "steemit/0.1", "format": "markdown", "links": ["https://en.wikipedia.org/wiki/Comparison_of_accounting_software", "https://coinmarketcap.com/", "http://cryptofolio.info/"], "image": ["https://steemitimages.com/DQmY8SEQixrGpxE6mRE6XiDxdr64Uq126P2zvitSti3DMZd/image.png"], "tags": ["howto", "excel", "cryptocurrency", "bitcoin", "money"]}"
created2017-08-29 21:48:45
last_update2017-08-30 08:05:03
depth0
children11
net_rshares397,225,563,122
last_payout2017-09-05 21:48:45
cashout_time1969-12-31 23:59:59
total_payout_value1.128 SBD
curator_payout_value0.230 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3,774
author_reputation360,301,994,866
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars0
author_curate_reward""
vote details (21)
@susueng ·
Is it possible to update automatically at certain intervals?
For example, how do I apply a module like OnTime Now + TimeValue ("00:00:30"), "AddCell"?
properties (22)
post_id11,438,876
authorsusueng
permlinkre-konstantint-cryptocurrency-accounting-in-excel-20170830t030113634z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-08-30 03:00:51
last_update2017-08-30 03:00:51
depth1
children1
net_rshares0
last_payout2017-09-06 03:00:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length150
author_reputation2,570,395,782,768
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@konstantint · (edited)
Of course you can also add logic to recalculate the sheet automatically at regular intervals. One way to do this could be to add a new module with, for example, the following code:

```
Private Running As Boolean

Public Sub StartTimer()
    Running = True
    Call TimerEvent
End Sub

Public Sub StopTimer()
    Running = False
End Sub

Public Sub TimerEvent()
    Workbooks("Book1").Worksheets(1).Calculate
    If Running Then
        Application.OnTime Now + TimeValue("00:00:10"), "TimerEvent"
    End If
End Sub
```
(Note that you'd need to replace "Book1" with the appropriate name, or simply use `ActiveWorkbook` in place of `Workbooks("Book1")`, although then the timer will be recalculating whatever workbook you have open at the moment).

You can start the timer by running the `StartTimer` macro (using the "Run" button) and stop it using `StopTimer`.

It might make sense to also add something like this to the code of `ThisWorkbook` module, so that the timer will start and stop automatically:
```
Private Sub Workbook_Open()
    Call StartTimer
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call StopTimer
End Sub
```
properties (22)
post_id11,458,144
authorkonstantint
permlinkre-susueng-re-konstantint-cryptocurrency-accounting-in-excel-20170830t083538814z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-08-30 08:35:42
last_update2017-08-30 08:37:36
depth2
children0
net_rshares0
last_payout2017-09-06 08:35:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,150
author_reputation360,301,994,866
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@maxabit ·
$0.08
This is a really useful!

I am pleased to announce that your post has been featured in Max Curation Edition No.6 published on Steemit.

You can take a look at it [HERE](https://steemit.com/community/@maxabit/best-of-steemit-max-curation-edition-no-6-find-gems-on-steemit-2017830t22412437z).

Congratulations! Upvoted and resteemed.
👍  ,
properties (23)
post_id11,493,726
authormaxabit
permlinkre-konstantint-cryptocurrency-accounting-in-excel-20170830t164539434z
categoryhowto
json_metadata"{"app": "steemit/0.1", "links": ["https://steemit.com/community/@maxabit/best-of-steemit-max-curation-edition-no-6-find-gems-on-steemit-2017830t22412437z"], "tags": ["howto"]}"
created2017-08-30 16:45:42
last_update2017-08-30 16:45:42
depth1
children2
net_rshares23,015,768,358
last_payout2017-09-06 16:45:42
cashout_time1969-12-31 23:59:59
total_payout_value0.059 SBD
curator_payout_value0.017 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length331
author_reputation4,410,059,454,176
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@konstantint ·
Thanks for the appreciation!
properties (22)
post_id11,502,214
authorkonstantint
permlinkre-maxabit-re-konstantint-cryptocurrency-accounting-in-excel-20170830t183725257z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-08-30 18:37:27
last_update2017-08-30 18:37:27
depth2
children1
net_rshares0
last_payout2017-09-06 18:37:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length28
author_reputation360,301,994,866
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@maxabit ·
You're welcome!
properties (22)
post_id11,677,068
authormaxabit
permlinkre-konstantint-re-maxabit-re-konstantint-cryptocurrency-accounting-in-excel-20170901t160930702z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-09-01 16:09:33
last_update2017-09-01 16:09:33
depth3
children0
net_rshares0
last_payout2017-09-08 16:09:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length15
author_reputation4,410,059,454,176
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@karthik2rock ·
$0.05
Amazing post, thanks a ton.
👍  
properties (23)
post_id11,494,363
authorkarthik2rock
permlinkre-konstantint-cryptocurrency-accounting-in-excel-20170830t165309429z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-08-30 16:53:09
last_update2017-08-30 16:53:09
depth1
children0
net_rshares14,583,472,441
last_payout2017-09-06 16:53:09
cashout_time1969-12-31 23:59:59
total_payout_value0.035 SBD
curator_payout_value0.011 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length27
author_reputation0
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@lturner ·
$0.07
This is a very valuable tutorial to anyone with a few types of cryptocurrency. I'm resteeming so my husband can read - he's our account manager and definitely better at Excel than I am, though I'm very intrigued to discover you can add commands to Excel this way.
👍  ,
properties (23)
post_id11,535,641
authorlturner
permlinkre-konstantint-cryptocurrency-accounting-in-excel-20170831t034413192z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-08-31 03:44:12
last_update2017-08-31 03:44:12
depth1
children0
net_rshares22,113,350,667
last_payout2017-09-07 03:44:12
cashout_time1969-12-31 23:59:59
total_payout_value0.056 SBD
curator_payout_value0.016 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length263
author_reputation4,547,553,088,751
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@cryptoblock ·
Nice post man! do you think I can apply this to openoffice? I dont know too much about visualbasic :S Thanks a lot! very usefull post!!
properties (22)
post_id11,826,702
authorcryptoblock
permlinkre-konstantint-cryptocurrency-accounting-in-excel-20170903t121255284z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-09-03 12:12:54
last_update2017-09-03 12:12:54
depth1
children1
net_rshares0
last_payout2017-09-10 12:12:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length135
author_reputation0
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@konstantint ·
Yes, you can do the same in OpenOffice as well. 

Go to *Tools ⇒ Macros ⇒ Organize Macros ⇒ OpenOffice Basic...*, create a new module under your current document, and paste the following, slightly modified, version of the code in the newly opened editor window:

```
Public Function HttpGet(ByVal requestUrl As String) As String
    Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    With http
        .Open "GET", requestUrl, True
        .Send ""
        .WaitForResponse 10
        HttpGet = .ResponseText
    End With
End Function

Public Function GetCryptoCurrencyPrice(ByVal name As String, ByVal baseCurrency As String, Optional cacheBuster As Variant) As Double
    GetCryptoCurrencyPrice = -1#
    json = HttpGet("https://api.coinmarketcap.com/v1/ticker/" & name & "/?convert=" & baseCurrency)
    
    For Each Line In Split(json)
        If found Then
            GetCryptoCurrencyPrice = CDbl(Mid(Line, 2, Len(Line) - 3))
            Exit Function
        End If
        If Line = """price_" & LCase(baseCurrency) & """:" Then
            found = True
        End If
    Next
End Function
```
properties (22)
post_id11,874,447
authorkonstantint
permlinkre-cryptoblock-re-konstantint-cryptocurrency-accounting-in-excel-20170903t232907870z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2017-09-03 23:29:09
last_update2017-09-03 23:29:09
depth2
children0
net_rshares0
last_payout2017-09-10 23:29:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,111
author_reputation360,301,994,866
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@adrianscott · (edited)
Nice article, I've posted a link to it on https://Fresherblock.com (let me know if you'd like an invite)
👍  
properties (23)
post_id12,026,438
authoradrianscott
permlinkre-konstantint-cryptocurrency-accounting-in-excel-20170905t162813632z
categoryhowto
json_metadata"{"app": "steemit/0.1", "links": ["https://Fresherblock.com"], "tags": ["howto"]}"
created2017-09-05 16:28:12
last_update2017-09-05 16:29:06
depth1
children0
net_rshares1,492,458,758
last_payout2017-09-12 16:28:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length104
author_reputation54,394,570,956
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@mckibbinusa ·
Useful and instructive, thanks!
properties (22)
post_id23,552,120
authormckibbinusa
permlinkre-konstantint-cryptocurrency-accounting-in-excel-20180104t153957108z
categoryhowto
json_metadata"{"app": "steemit/0.1", "tags": ["howto"]}"
created2018-01-04 15:40:03
last_update2018-01-04 15:40:03
depth1
children0
net_rshares0
last_payout2018-01-11 15:40:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length31
author_reputation15,930,236,457
root_title"Cryptocurrency Accounting in Excel"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000