My Fitbit Data



Solving My Fitbit data Problem
Subject: VBA code to combine Fitbit excel files into one

I purchase a Fitbit Alta HR in 2017, and since then I wear it and never take it off unless for charging. Fitbit Alta HR is a very nice slim device, but unfortunately there was no way to upload my previous data from my old device to my Fitbit, this was not the only issue with Fitbit data, now; after three years still we can’t download Fitbit data in one file, if you want to do this (each time) you need to send a request to Fitbit team and they will prepare the file for you!! Instead, Fitbit site allow you to download your data as month by month, in my case I will have almost 32 files.

Solving the Problem: After downloading the excel files and look at them, I decide to write a code to help me combine all the current 32 files and any coming once into one data file. First I start thinking to use Python to do this task, but after second thought I will use the Excel file and VBA macro coding to do it.
Here in coming paragraph I will post about the general idea and some codes that i use.

General Idea: I will use same structure of Fitbit file and name it as “fitbit_All_data_ali”, in this file we will create new tab and name it Main. In the Main tab we will create several buttons using excel developer tools and will write the macro VBA code for each task we need to operate.

Tabs in our file: Main: Contain buttons and summary about my data.
Body, Food, Sleep, Activities and Food Log. Food Log tab will store the data such as calories, fibers, fat and so-on., all those tabs will be filled with a copied data from each Fitbit data file.

Here are some VBA codes that I use and what it’s purpose .

Code:
‘ Get current path.
the_path = Application.ActiveWorkbook.Path
The path on the current excel file.
Code:
the_All_Data_file = ThisWorkbook.Name
Get current excel file name
Code:
Workbooks.Open Filename:=thepath + my_source_Filename
Open a file
Code:
Windows(my_source_Filename).Activate
Sheets(“Foods”).Select
Range(“A2:B31”).Select
Selection.Copy
Goto fitbit file, goto food sheet, select the data copy it.
Code:
Application.CutCopyMode = False
Workbooks(my_source_Filename).Close SaveChanges:=False
Close an open excel file.
Code:
Range(“A3”).Select
Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
To insert a black Row
Code:
sname = ActiveSheet.Name
Get current sheet name
Code:
Function go_next_sheet() As String

‘ This code will go to next sheet if there is one, if not will return ‘last’
go_next_sheet = “no”
Dim sht As Worksheet
Set sht = ActiveSheet

On Error Resume Next

If sht.Next.Visible xlSheetVisible Then
If Err 0 Then
go_next_sheet = “last”
End If

Set sht = sht.Next
End If

sht.Next.Activate
On Error Resume Next

End Function

if there is no more tabs or sheets, function will return “last”


Final Results: After i run the code, I have an Excel file contain all my Fitbit data in one place. Mission Accomplished



To Download my Python code (.py) files Click-Here




Follow me on Twitter..





  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: