Let \( x \) represent the total number of units in the apartment building. According to the problem, 5% of the total units are vacant, which can be expressed as:
\[ 0.05x = 18 \]
To find \( x \), we can solve the equation by dividing both sides by 0.05:
\[ x = \frac{18}{0.05} \]
Calculating the right side:
\[ x = 18 \div 0.05 = 18 \times 20 = 360 \]
Therefore, the total number of units in the apartment building is
\[ \boxed{360} \]