Macro clear cell value & also its code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
I have a worksheet that i use for invoices.
Once the invoice is printed i then press a button to run a macro which then clears the values that i have just typed into the cells.

The code on the worksheet has just been changed but the macro which clears the cells is still the same.
The problem that i have now is that not only does the macro clear the cells but it also deletes the code etc in that cell.

Below is the macro code that i use to clear the cell values.

Code:
Sub INVCUSTOMERINFO()  Application.EnableEvents = False
  '   *** CUSTOMER DETAILS ***
  Range("G13:I18").ClearContents
  
  '   *** JOB DETAILS ***
  Range("N14:O18").ClearContents
  
  Range("G13").Select
  
  Application.EnableEvents = True
End Sub


Below is the code in each cell that is used to return the requested values but is then deleted when the macro has run.
Code:
=INDEX(DATABASE!R:R,$H$13)

Can you advise how to edit or replace the existing macro code so it only clears what i have typed as opposed to also clearing its code which i would like left behind so next invoice is then ready to use again.

Thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Why not just change the ranges in the code, to only clear the cells you type into.
 
Upvote 0
Just change these 2 lines
Code:
Range("G13:I18").ClearContents
  
Range("N14:O18").ClearContents
so that they only look at the cells you want to clear
 
Upvote 0
Still not understanding you sorry.
The codes that pull the info from the DATABASE sheet are in cells G14:G18 & N14:N17

I then write in cells G27:O36 & also G47:G51
 
Upvote 0
If the you want to keep the formulae & they are in G13:I18 and N14:O18.
Simply don't run that macro.
 
Upvote 0
Ok
I think that is where i lost you.
So my question is when i now come to issue a new invoice say the next day i assume going by the above advice the old customers info will still be in those cells.

Correct ?
 
Upvote 0
Do the ranges in your code contain formulae, or hard values?
If formulae, then just change those ranges to the ranges where you type in the values.
 
Upvote 0
Here is some info for you.
Cell G13 has drop down list BUT
Code:
=IF(ISERROR(MATCH(G13,DATABASE!A:A,0)),"",MATCH(G13,DATABASE!A:A,0))

G14:G18 has address post code etc etc BUT also has a formula like
Code:
=INDEX(DATABASE!R:R,$H$13)

N14:N17 vin number, registration nu,mber etc etc BUT also has a formula like
Code:
=INDEX(DATABASE!D:D,$H$13)

The other cell range is where i type what was purchased etc but isnt affected

So lets say the drop down code pulls the info & now in cell G14 is the first line of his adress ex 14 MALLARDS CLOSE there is also the formula there =INDEX(DATABASE!R:R,$H$13)

So when the macro is run the 14 MALLARDS CLOSE is cleared BUT so is the formula =INDEX(DATABASE!R:R,$H$13)
 
Upvote 0
A cell either has a formula, or a value. It CANNOT have both.
So do they have formulae or not?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top