Paste Special If statement

J

Jeremy

I'm trying to write code for a paste special if statement and need help. I
want it to perform like this:

If C1 (calculated from other formula) is equal to 1, then paste that value
into D1, if it is equal to 0, then do nothing.

I'm trying to get a column that identifies which items in the first column
were ever calculated to equal one and then apply conditional formatting.

Thanks
 
G

Gary''s Student

Put the following worksheet event macro in the worksheet code area:

Private Sub Worksheet_Calculate()
If Range("C1").Value = 1 Then
Range("D1").Value = 1
End If
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window


To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
 
J

Jeremy

Yea, I had tried that before and it didn't work, still can't seem to.

I have pasted the code, put a 1 in the cell C1, I saved the book, hit F9 to
calculate etc and nothing.
 
J

Jeremy

Nevermind, I got it. I think there was an old definition or something in
there. I deleted the cells instead of just clearing and it worked fine.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top