If you find yourself in the unfortunate position of having to delete a credit memo or order in Magento then take a deep breath and keep reading. I found my self in this very position. At first I was just going to run some sql to remove the orders and credit memo, but that started getting pretty messy. So Below is my solution for deleting an order and Deleting a credit memo attached to an order(but not deleting the order).

Before proceeding Please Note: This was written using Magento Version 1.4.1.1. Because of the vast differences between version this may or may not work on other version. Test anything on a staging site before trying to apply to a production site.

To run the following code snippets you need to add them to an Admn controller action, then go to this action in the admin area. What controller you temporarily add this to is your choice.

        //Delete two orders
    	/* */
    	$orders = Mage::getModel('sales/order')->getCollection()
    		->addAttributeToFilter('increment_id', array('in', array('XXX000700', 'XXX000700-1')));
    	if(count($orders) delete();
	    	}
    	} else {
    		Die("incorect number of orders to delete.");
    	}

Now We Delete a Credit Memo we did not want

        //Now Delete the Refund for an order but do not delete the order.
    	$order = Mage::getModel('sales/order')->loadByIncrementId('XXX000320');
    	//Delete Credit Memo
    	$creditMemos = $order->getCreditmemosCollection();
    	foreach($creditMemos as $cm){	//cancel each credit memo for the order
    		$state = $cm->getState();
    		if($state == 3){//Cancled
    			continue;
    		}
    		$cm->cancel()
    			->save()
    			->getOrder()->save();	//Needed to save the order to apply the canceled credit memo to all order items.

    		$cm->delete();
    	}

After running the above code I did need to edit the refund values for the order in this table: sales_flat_order

when canceling the credit memo it changed the offline refund amount instead of the online refund amount.