ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macros in Formulas (https://www.excelbanter.com/excel-programming/403375-macros-formulas.html)

dr

Macros in Formulas
 
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

Don Guillett

Macros in Formulas
 
if range("a2")0 then sheets("sheet1").range("a2").value="x"

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"DR" wrote in message
...
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



JLGWhiz

Macros in Formulas
 
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

"DR" wrote:

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


dr

Macros in Formulas
 
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?

"JLGWhiz" wrote:

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

"DR" wrote:

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


dr

Macros in Formulas
 
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
"JLGWhiz" wrote:

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

"DR" wrote:

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


Don Guillett

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"DR" wrote in message
...
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
"JLGWhiz" wrote:

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

"DR" wrote:

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




All times are GMT +1. The time now is 11:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com