As you branch out, you'll often find you want to substitute the yarn called for in a pattern for any number of reasons.
First, what is the weight of the yarn? Worsted? Sport weight? You need to select a yarn that is in the same weight class. If you don't, you won't be able to obtain the correct gauge and your project will not be the correct size. Don't even try it. It won't work.
If you're using a heavier weight yarn such as bulky, you can try two strands of worsted weight yarn held together throughout. Check your gauge carefully. Once you achieve the gauge, the resulting fabric should be neither too loose nor too stiff (unless of course that is the intent of the design).
Second, think about the fiber content of the original yarn. Although you may your project turns out perfect if you substitute chenille for cotton, these two fibers produce a knitted garment with entirely different looks and feel. The way the knitted fabric will drape is another consideration in terms of fiber. For more information, see The Right Yarn For The Project.
Third, you want to make sure you have purchased sufficient yarn from the same dye lot to complete your project. You can no longer purchase 8 balls of Brand X because you are now going to be using Brand Y. Do not ever substitute by buying the same number of balls or by the total number of ounces or grams. There are differences in the number of yards in even closely equivalent yarns; if the fiber content is different, you will likely find a difference in the yardage because some fibers are heavier than others (cotton is heavier than wool and will have fewer yards, all things being equal). You must substitute by making sure you have bought the equivalent number of yards or meters.
Your pattern should indicate that the original yarn had, for example, 100 yards per ball. You needed 8 balls. that is a total of 800 yards. The yarn you selected has 85 yards per ball. Divide 800 by 85 and you'll see you need 9.4 balls of the new yarn. Round this up to 10; do not round down. It's always a good idea to purchase one extra skein in addition to the number you've come up with.
If you are substituting by double stranding, you must double the yardage you will need to purchase.