Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default exit macro after test of cell value

I want a macro executed from a certain row only. Other parts of macro are
copied from knowledge base. So far so good! My knowledge of Vbasic is not
enough therefore my question to you to write one statement: IF etc....
Macro:
Sub Extra3lines()

Dim c As Range

'the cell is saved as variable
Set c = Selection

'In cell ADx is the row number - ADx is in same row as c
'Exit macro when row number of c is not equal to value in cell ADx
' If c < ADx then End sub << I am looking for correct syntax

'insert 3 rows above selected row
Range(c, c.Offset(2, 0)).EntireRow.Insert

'force saving sheet with new name - once per month
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\Owner\My
Documents\VvEAH\2007\VvEAH_Bookdoc Expl " & Format(Now, "yyyy-mm") & ".xls"

End Sub

Thanks for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default exit macro after test of cell value

If c.Row < Range(ADx).Value Then Exit Sub

Mike F
"Pepestru" wrote in message
...
I want a macro executed from a certain row only. Other parts of macro are
copied from knowledge base. So far so good! My knowledge of Vbasic is not
enough therefore my question to you to write one statement: IF etc....
Macro:
Sub Extra3lines()

Dim c As Range

'the cell is saved as variable
Set c = Selection

'In cell ADx is the row number - ADx is in same row as c
'Exit macro when row number of c is not equal to value in cell ADx
' If c < ADx then End sub << I am looking for correct
syntax

'insert 3 rows above selected row
Range(c, c.Offset(2, 0)).EntireRow.Insert

'force saving sheet with new name - once per month
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\Owner\My
Documents\VvEAH\2007\VvEAH_Bookdoc Expl " & Format(Now, "yyyy-mm") &
".xls"

End Sub

Thanks for your help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default exit macro after test of cell value

Mike thanks sofar. My fault: I meant with ADx the cell in Col AD and Row c. I
changed the If statement to: If c.Row < Range(Cells(c.Row,"AD").Value then
exit
But I get a Viual Basic error. Whats wrong?


"Mike Fogleman" wrote:

If c.Row < Range(ADx).Value Then Exit Sub

Mike F
"Pepestru" wrote in message
...
I want a macro executed from a certain row only. Other parts of macro are
copied from knowledge base. So far so good! My knowledge of Vbasic is not
enough therefore my question to you to write one statement: IF etc....
Macro:
Sub Extra3lines()

Dim c As Range

'the cell is saved as variable
Set c = Selection

'In cell ADx is the row number - ADx is in same row as c
'Exit macro when row number of c is not equal to value in cell ADx
' If c < ADx then End sub << I am looking for correct
syntax

'insert 3 rows above selected row
Range(c, c.Offset(2, 0)).EntireRow.Insert

'force saving sheet with new name - once per month
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\Owner\My
Documents\VvEAH\2007\VvEAH_Bookdoc Expl " & Format(Now, "yyyy-mm") &
".xls"

End Sub

Thanks for your help




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default exit macro after test of cell value

If c.Row < Cells(c.Row, "AD").Value Then Exit Sub
or
If c.Row < Range("AD" & c.Row).Value Then Exit Sub

Mike F

"Pepestru" wrote in message
...
Mike thanks sofar. My fault: I meant with ADx the cell in Col AD and Row
c. I
changed the If statement to: If c.Row < Range(Cells(c.Row,"AD").Value
then
exit
But I get a Viual Basic error. Whats wrong?


"Mike Fogleman" wrote:

If c.Row < Range(ADx).Value Then Exit Sub

Mike F
"Pepestru" wrote in message
...
I want a macro executed from a certain row only. Other parts of macro
are
copied from knowledge base. So far so good! My knowledge of Vbasic is
not
enough therefore my question to you to write one statement: IF etc....
Macro:
Sub Extra3lines()

Dim c As Range

'the cell is saved as variable
Set c = Selection

'In cell ADx is the row number - ADx is in same row as c
'Exit macro when row number of c is not equal to value in cell ADx
' If c < ADx then End sub << I am looking for correct
syntax

'insert 3 rows above selected row
Range(c, c.Offset(2, 0)).EntireRow.Insert

'force saving sheet with new name - once per month
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\Owner\My
Documents\VvEAH\2007\VvEAH_Bookdoc Expl " & Format(Now, "yyyy-mm") &
".xls"

End Sub

Thanks for your help






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default exit macro after test of cell value

Mike, this is what I was looking for! It works fine.
Thanks,
Paul

"Mike Fogleman" wrote:

If c.Row < Cells(c.Row, "AD").Value Then Exit Sub
or
If c.Row < Range("AD" & c.Row).Value Then Exit Sub

Mike F

"Pepestru" wrote in message
...
Mike thanks sofar. My fault: I meant with ADx the cell in Col AD and Row
c. I
changed the If statement to: If c.Row < Range(Cells(c.Row,"AD").Value
then
exit
But I get a Viual Basic error. Whats wrong?


"Mike Fogleman" wrote:

If c.Row < Range(ADx).Value Then Exit Sub

Mike F
"Pepestru" wrote in message
...
I want a macro executed from a certain row only. Other parts of macro
are
copied from knowledge base. So far so good! My knowledge of Vbasic is
not
enough therefore my question to you to write one statement: IF etc....
Macro:
Sub Extra3lines()

Dim c As Range

'the cell is saved as variable
Set c = Selection

'In cell ADx is the row number - ADx is in same row as c
'Exit macro when row number of c is not equal to value in cell ADx
' If c < ADx then End sub << I am looking for correct
syntax

'insert 3 rows above selected row
Range(c, c.Offset(2, 0)).EntireRow.Insert

'force saving sheet with new name - once per month
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\Owner\My
Documents\VvEAH\2007\VvEAH_Bookdoc Expl " & Format(Now, "yyyy-mm") &
".xls"

End Sub

Thanks for your help






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
Run a macro on exit More Macro Help Needed Excel Programming 3 January 11th 10 11:34 PM
Run macro on exit Steve Excel Discussion (Misc queries) 12 October 25th 09 01:43 PM
Macro on exit cell nonshedders Excel Discussion (Misc queries) 1 April 12th 06 12:41 PM
How to test cell contents in a macro? JennyGard Excel Programming 4 February 22nd 06 03:08 PM
Run Macro on cell exit Kelly Excel Programming 7 May 5th 04 09:42 PM


All times are GMT +1. The time now is 10:06 PM.

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"