Kent's answer works well for a spare part; for universal insertion when entering a wildcard command interactively, you can insert any expression (not just variables, but also functions, etc.) through <C-R><C-R>=(they should be printed as Ctrl+ R, and not literally):
:substitute/<C-R><C-R>=b:myvar<CR>/replacement/<CR>
Inside the script use :execute:
:execute 'substitute/' . b:myvar . '/replacement/'
source
share