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
 
This gets better as we go along.
I have applied the code below in cell G16
Code:
=IFERROR(IF(INDEX(DATABASE!T:T,$H$13)=0,"",INDEX(DATABASE!T:T,$H$13)),"")
Now when i select this customer as opposed to seeing 0 in the cell G16 it is now empty, perfect.

I then use the same code but change the DATABASE row letter & apply it to each cell G14 G15 G17 G18
Code:
=IFERROR(IF(INDEX(DATABASE!V:V,$H$13)=0,"",INDEX(DATABASE!T:T,$H$13)),"")

Now what i see is the reverse, meaning these cells now show 0

So where as before the cell on DATABASE sheet was empty the INV sheet showed 0
Now this is fixed with your new code

So where now the cells on DATABASE sheet have a value the INV sheet started showing 0
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You've only changed the column reference in the 1st index, you need to change it in both.
 
Upvote 0
That was just a reference so I do t have to supply the code for all of them.

I used the same code but I replaced the T to reflect the DATABASE row so
T U B W etc etc
 
Upvote 0
I'm afraid I haven't got a clue what you mean.
 
Upvote 0
What dont you understand ?

What i see now is 0 in each cell on the INV sheet when there is a value in the rows on the DATABASE sheet.
Do you understand the above ?

In cell G16 is the following code.
Code:
=IFERROR(IF(INDEX(DATABASE!T:T,$H$13)=0,"",INDEX(DATABASE!T:T,$H$13)),"")

In cell G17 is the following code.
Code:
=IFERROR(IF(INDEX(DATABASE!U:U,$H$13)=0,"",INDEX(DATABASE!T:T,$H$13)),"")

In cell G18 is the following code.
Code:
=IFERROR(IF(INDEX(DATABASE!V:V,$H$13)=0,"",INDEX(DATABASE!T:T,$H$13)),"")
Do you understand the above ?

This is what i had recently seen on the INV sheet
G14 a value from DATABASE sheet
G15 a value from DATABASE sheet
G16 0
G17 a value from DATABASE sheet
G18 a value from DATABASE sheet

Now with the code you advised its reversed,so its now like this.

G14 0
G15 0
G16 a value from DATABASE sheet
G17 0
G18 0
Do you understand the above ?
 
Upvote 0
I told you what was wrong in post#32
Your index functions are looking at different columns
 
Upvote 0
I now got it.
I dont understand all that is written so sometimes a code is much helpfull.

Now sorted many thanks for the help last night & today
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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