Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Starting Auto_Close macro based on an IF statement

I'm over my head --
I run an auto_close macro to retrieve and save data collected during a user
session. The macro takes all rows with data, copies them to a folder, then
clears the collection sheet for next session.
If there is NO DATA collected, I want to end the macro right away.
Otherwise, I'm getting an error saying Excel can't move things off the
worksheet because data may be lost . . . to paraphrase I think it's a
runtime error 1004?

Here is what I came up w/, but not sure if it's even close -- it doesn't
work though.

If Sheets("Worksheet") & Range("A3") = "" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Else
Workbooks.Open Filename:="W:\. . .

Where if A# < "", then I want to run the macro. Any help?

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Starting Auto_Close macro based on an IF statement

hi
you have....
If Sheets("Worksheet") & Range("A3") = "" Then
that should be...
If Sheets("Worksheet").Range("A3") = "" Then

ie replace & with .
also loose the end if after activeworkbook.close
i see nothing else wrong in theory but i haven't tested.
you are on the right track. just a syntax thing.
Regards
FSt1

"questor" wrote:

I'm over my head --
I run an auto_close macro to retrieve and save data collected during a user
session. The macro takes all rows with data, copies them to a folder, then
clears the collection sheet for next session.
If there is NO DATA collected, I want to end the macro right away.
Otherwise, I'm getting an error saying Excel can't move things off the
worksheet because data may be lost . . . to paraphrase I think it's a
runtime error 1004?

Here is what I came up w/, but not sure if it's even close -- it doesn't
work though.

If Sheets("Worksheet") & Range("A3") = "" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Else
Workbooks.Open Filename:="W:\. . .

Where if A# < "", then I want to run the macro. Any help?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Starting Auto_Close macro based on an IF statement

I get a VB Compile Error: "Block If without End If"

Since I tried this with A3 being blank, I figured it would end quick (save &
close) w/out running the rest of the macro -- which I want to run if A3 isn't
blank.

I think that's why I stuck the "End If" in there to begin with.

Any ideas on getting around the compile error? You do think I'm on the
right track tho -- basically conditionally running a macro or just closing if
""? Didn't know if I should b on a completely different track or not.

Thanks.

"FSt1" wrote:

hi
you have....
If Sheets("Worksheet") & Range("A3") = "" Then
that should be...
If Sheets("Worksheet").Range("A3") = "" Then

ie replace & with .
also loose the end if after activeworkbook.close
i see nothing else wrong in theory but i haven't tested.
you are on the right track. just a syntax thing.
Regards
FSt1

"questor" wrote:

I'm over my head --
I run an auto_close macro to retrieve and save data collected during a user
session. The macro takes all rows with data, copies them to a folder, then
clears the collection sheet for next session.
If there is NO DATA collected, I want to end the macro right away.
Otherwise, I'm getting an error saying Excel can't move things off the
worksheet because data may be lost . . . to paraphrase I think it's a
runtime error 1004?

Here is what I came up w/, but not sure if it's even close -- it doesn't
work though.

If Sheets("Worksheet") & Range("A3") = "" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Else
Workbooks.Open Filename:="W:\. . .

Where if A# < "", then I want to run the macro. Any help?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Starting Auto_Close macro based on an IF statement

If Sheets("Worksheet").Range("A3").value = "" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
Else
Workbooks.Open Filename:="W:\. . .


If this doesn't help, it's time to post your current code.

questor wrote:

I get a VB Compile Error: "Block If without End If"

Since I tried this with A3 being blank, I figured it would end quick (save &
close) w/out running the rest of the macro -- which I want to run if A3 isn't
blank.

I think that's why I stuck the "End If" in there to begin with.

Any ideas on getting around the compile error? You do think I'm on the
right track tho -- basically conditionally running a macro or just closing if
""? Didn't know if I should b on a completely different track or not.

Thanks.

"FSt1" wrote:

hi
you have....
If Sheets("Worksheet") & Range("A3") = "" Then
that should be...
If Sheets("Worksheet").Range("A3") = "" Then

ie replace & with .
also loose the end if after activeworkbook.close
i see nothing else wrong in theory but i haven't tested.
you are on the right track. just a syntax thing.
Regards
FSt1

"questor" wrote:

I'm over my head --
I run an auto_close macro to retrieve and save data collected during a user
session. The macro takes all rows with data, copies them to a folder, then
clears the collection sheet for next session.
If there is NO DATA collected, I want to end the macro right away.
Otherwise, I'm getting an error saying Excel can't move things off the
worksheet because data may be lost . . . to paraphrase I think it's a
runtime error 1004?

Here is what I came up w/, but not sure if it's even close -- it doesn't
work though.

If Sheets("Worksheet") & Range("A3") = "" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Else
Workbooks.Open Filename:="W:\. . .

Where if A# < "", then I want to run the macro. Any help?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default Starting Auto_Close macro based on an IF statement

Kept getting the compile error. I inserted "End if" on the 2nd to last line
just above "End Sub" and it seemed to do the trick / close the statement?.
Sorry to say I really don't understand much of this stuff (and my code is a
cluged cluster of recordings and written commands). I'm just happy when it
works. So far, it looks like it's doing just what I want. Still learning . .
..

Thanks & Best Regards ~ "Questor"

"Dave Peterson" wrote:

If Sheets("Worksheet").Range("A3").value = "" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
Else
Workbooks.Open Filename:="W:\. . .


If this doesn't help, it's time to post your current code.

questor wrote:

I get a VB Compile Error: "Block If without End If"

Since I tried this with A3 being blank, I figured it would end quick (save &
close) w/out running the rest of the macro -- which I want to run if A3 isn't
blank.

I think that's why I stuck the "End If" in there to begin with.

Any ideas on getting around the compile error? You do think I'm on the
right track tho -- basically conditionally running a macro or just closing if
""? Didn't know if I should b on a completely different track or not.

Thanks.

"FSt1" wrote:

hi
you have....
If Sheets("Worksheet") & Range("A3") = "" Then
that should be...
If Sheets("Worksheet").Range("A3") = "" Then

ie replace & with .
also loose the end if after activeworkbook.close
i see nothing else wrong in theory but i haven't tested.
you are on the right track. just a syntax thing.
Regards
FSt1

"questor" wrote:

I'm over my head --
I run an auto_close macro to retrieve and save data collected during a user
session. The macro takes all rows with data, copies them to a folder, then
clears the collection sheet for next session.
If there is NO DATA collected, I want to end the macro right away.
Otherwise, I'm getting an error saying Excel can't move things off the
worksheet because data may be lost . . . to paraphrase I think it's a
runtime error 1004?

Here is what I came up w/, but not sure if it's even close -- it doesn't
work though.

If Sheets("Worksheet") & Range("A3") = "" Then
ActiveWorkbook.Save
ActiveWorkbook.Close
End If
Else
Workbooks.Open Filename:="W:\. . .

Where if A# < "", then I want to run the macro. Any help?


--

Dave Peterson

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
Starting A Macro zephyr Excel Discussion (Misc queries) 2 November 10th 06 12:03 PM
starting a macro at startup chip_pyp Excel Discussion (Misc queries) 1 March 22nd 06 06:59 PM
Starting a macro with the IF function THW Excel Worksheet Functions 4 June 19th 05 05:40 PM
How can I assign a range starting cell based on a variable locati. feman007 Excel Discussion (Misc queries) 1 March 9th 05 11:41 PM
How can I assign a range starting cell based on a variable locati. feman007 Excel Worksheet Functions 3 March 9th 05 11:40 PM


All times are GMT +1. The time now is 11:54 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"