Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to If Statement

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,696
Default Macro to If Statement

May as well put the If into your VB.

Wherever the macro is,
Private Sub macroname()
'comments
Put your IF x Then
Macro code
End If
End Sub

"JHusker" wrote:

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Macro to If Statement

You can't (reliably) run a macro from a worksheet cell. A cell can
call upon a function written in VBA, but that function cannot change
any part of the Excel environment, such as changing the value of
another cell. A function called from a worksheet cell (directly or
indirectly) can only return a value to the cell from which it was
called.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email is on the web site)
USA Central Daylight Time (-5:00 GMT)


On Fri, 10 Oct 2008 13:38:08 -0700, JHusker
wrote:

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 364
Default Macro to If Statement

Macros can not be assigned to a formula.

You can use User Defined Function to a formula...

"JHusker" wrote:

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to If Statement

This is what I want to do:
if the value of the cell=0, then I want the whole row to be hidden......is
this possible?

"Chip Pearson" wrote:

You can't (reliably) run a macro from a worksheet cell. A cell can
call upon a function written in VBA, but that function cannot change
any part of the Excel environment, such as changing the value of
another cell. A function called from a worksheet cell (directly or
indirectly) can only return a value to the cell from which it was
called.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email is on the web site)
USA Central Daylight Time (-5:00 GMT)


On Fri, 10 Oct 2008 13:38:08 -0700, JHusker
wrote:

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Macro to If Statement

How do you write an IF into VB?

"Sean Timmons" wrote:

May as well put the If into your VB.

Wherever the macro is,
Private Sub macroname()
'comments
Put your IF x Then
Macro code
End If
End Sub

"JHusker" wrote:

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Macro to If Statement

In the Sheet's code module, use code like the following. Change the
tests of the row numbers to reflect the row(s) whose values you want
to test:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then
Exit Sub
End If
If Target.Row = 11 And Target.Row <= 15 Then
If Target.Value = 0 Then
Target.EntireRow.Hidden = True
Else
Target.EntireRow.Hidden = False
End If
End If
End Sub

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email is on the web site)
USA Central Daylight Time (-5:00 GMT)


On Fri, 10 Oct 2008 13:53:01 -0700, JHusker
wrote:

This is what I want to do:
if the value of the cell=0, then I want the whole row to be hidden......is
this possible?

"Chip Pearson" wrote:

You can't (reliably) run a macro from a worksheet cell. A cell can
call upon a function written in VBA, but that function cannot change
any part of the Excel environment, such as changing the value of
another cell. A function called from a worksheet cell (directly or
indirectly) can only return a value to the cell from which it was
called.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email is on the web site)
USA Central Daylight Time (-5:00 GMT)


On Fri, 10 Oct 2008 13:38:08 -0700, JHusker
wrote:

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,696
Default Macro to If Statement

It is possible. I suppose you'd want the code. :-(

You would probably get best results in the Excel Programming section...

I know you'd want to use soemthign such as

If Range("A1).Value = 0 Then
Selection.entireRow.Hidden
End If

But not sure of the function this would require...



"JHusker" wrote:

This is what I want to do:
if the value of the cell=0, then I want the whole row to be hidden......is
this possible?

"Chip Pearson" wrote:

You can't (reliably) run a macro from a worksheet cell. A cell can
call upon a function written in VBA, but that function cannot change
any part of the Excel environment, such as changing the value of
another cell. A function called from a worksheet cell (directly or
indirectly) can only return a value to the cell from which it was
called.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email is on the web site)
USA Central Daylight Time (-5:00 GMT)


On Fri, 10 Oct 2008 13:38:08 -0700, JHusker
wrote:

I want to assign a macro to an if statement. After I've recorded the macro,
how do I assign it to the "=if" formula?

Thanks in advance for the help!

~Joe


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro if and / or statement orquidea Excel Discussion (Misc queries) 4 April 4th 23 10:27 AM
If statement in macro orquidea Excel Discussion (Misc queries) 2 May 11th 08 08:19 PM
can i use an IF Statement to run a macro? Davidrowland88 Excel Worksheet Functions 2 February 11th 05 12:45 PM
if statement in Macro John Excel Worksheet Functions 6 December 29th 04 07:17 PM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM


All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"