Macros in Formulas

  • Thread starter Thread starter DR
  • Start date Start date
D

DR

I am relatively new to macros and only know how to record a macro. I am
trying to use an if formula in a macro but am not sure how. What I need it
to do is if a value is = 0 then populate certain fields on a particular
worksheet, and if a particular value is greater than zero then populate
certain cells on a different worksheet. If there is no value then do nothing.

Please help,

DR
 
The term populate can mean different types of code execution, You can copy
from one place to populate another place or you can use an array to populate
a series of cells or you can directly equate the gaining cell(s) to the
source cell(s). You can also use different techniques for acquiring the
source data. So, it helps if you can be specific when stating your
requirements as to where your source data will be, how many cells are in the
range and how much of it you want to move at one shot.
The code below assumes one cell for the criteria range and one cell for the
receiving range, without any specific source data.

Sub zeroCrit()
If ActiveSheet.Cells(1, 1).Value = 0 Then
Range("B1") = 'Something
ElseIf ActiveSheet.Cells(1, 1).Value > 0 Then
Worksheets(2).Range("C1") = 'Something
End If
End Sub
 
Thanks for everyone's input. Another question: How do I tell it to skip to
the next row after it has pulled the data based on the if statement so that
it doesn't copy over what is already there?
 
I wrote a shortened version of what I need it to do just to see if it would
work and it doesn't. I don't know what I am doing wrong. I'm obviously in
over my head, but I don't know how else to accomplish what I need. Here is
the code I wrote:

Sub WOSeriesTabs()
If ActiveSheet.Cells(M8).Value = 0 Then
Worksheets(3).Range("B4") = A8
ElseIf ActiveSheet.Cells(M8).Value > 0 Then
Worksheets(2).Range("B4") = A8
End If
End Sub

Any help would be greatly appreciated!

DR
 
Look at it some more along with the suggestions. You'll figure it out if you
just think about it.
 

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

Back
Top