The son of the Reverend James Duncan Macfarlane, Macfarlane was educated at Magdalen College, Oxford, where he matriculated in 1876, graduating B.A. at St. Alban Hall in 1879.[5]
He was promoted substantive major on 5 January 1900, and was with the 1st battalion of his regiment as it went to South Africa to serve in the Second Boer War from 1900 to 1902. He took part in operations in the Orange Free State February to March 1900, including action at Vet River and Zand River; then moved to Transvaal where he took part in the occupation of Johannesburg and Pretoria in June 1900 and was present at the action on Zilikat's Nek in August 1900. He served with the battalion in Transvaal throughout the guerrilla phase of the war, and was temporary in command of the battalion from 20 February to 20 April 1902.[6] For his service in the war he was mentioned in despatches, received the Queen's Medal with three clasps, was appointed a Companion of the Distinguished Service Order (DSO), and received the brevet rank of lieutenant-colonel on 22 August 1902.[8]