Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I exit on blank cell?

I have a workbook with a ton of sheets. One macro calls the below
function and runs the below for each sheet, but bombs out when it hits
a sheet that is blank. What I would like to do is exit the below macro
once it reaches a sheet that has cell B4 as blank. I'm sure the code is
horrible (I'm a beginner), but I'm not sure why it doesn't work. It
just keeps going without exiting. Help please and thank you!?!?!


Sub Import_Files()

If Range("B4").Value = """" Then
Exit Sub
End If
Dim WB As Workbook
Set WB = Workbooks.Open(Filename:="N:\US\Index Investments\Equity
Management and Training\Index Research Group\Shared\Audit PCF Files\" &
Range("B4").Value)
'should try this. stupid vba so constricting
WB.Worksheets(1).Range("A1:E4").Copy
Destination:=Workbooks("Audit_Template").Worksheet s(3).Range("A6")
Range("A1:E45000").Select
Selection.Copy
Application.DisplayAlerts = False
WB.Close Savechanges:=False
Application.DisplayAlerts = True
Range("A6").Select
ActiveSheet.Paste
Range("A6").Select
Application.CutCopyMode = False
Range("F7").Select
ActiveCell.FormulaR1C1 = "=RC[-5]=R1C2"
Range("F7").Select
Selection.AutoFill Destination:=Range("F7:F45000")
Range("F7:F45000").Select
Range("A6:F6").Select
Range("F6").Activate
Selection.AutoFilter
Selection.AutoFilter Field:=6, Criteria1:="FALSE"
Rows("7:7").Select
Rows("7:45000").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter Field:=6, Criteria1:="TRUE"
Columns("F:F").Select
Selection.AutoFilter Field:=6
Selection.Delete Shift:=xlToLeft
Selection.AutoFilter
Range("A6").Select

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I exit on blank cell?


Range("B4").Value = """"

Since you use Value function, you shouldn't enter the value as """".
Just enter "" then it should work.


--
renegan
------------------------------------------------------------------------
renegan's Profile: http://www.excelforum.com/member.php...o&userid=10450
View this thread: http://www.excelforum.com/showthread...hreadid=538648

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How do I exit on blank cell?

Too many ""...

If Range("B4").Value = "" then exit sub
--
HTH...

Jim Thomlinson


" wrote:

I have a workbook with a ton of sheets. One macro calls the below
function and runs the below for each sheet, but bombs out when it hits
a sheet that is blank. What I would like to do is exit the below macro
once it reaches a sheet that has cell B4 as blank. I'm sure the code is
horrible (I'm a beginner), but I'm not sure why it doesn't work. It
just keeps going without exiting. Help please and thank you!?!?!


Sub Import_Files()

If Range("B4").Value = """" Then
Exit Sub
End If
Dim WB As Workbook
Set WB = Workbooks.Open(Filename:="N:\US\Index Investments\Equity
Management and Training\Index Research Group\Shared\Audit PCF Files\" &
Range("B4").Value)
'should try this. stupid vba so constricting
WB.Worksheets(1).Range("A1:E4").Copy
Destination:=Workbooks("Audit_Template").Worksheet s(3).Range("A6")
Range("A1:E45000").Select
Selection.Copy
Application.DisplayAlerts = False
WB.Close Savechanges:=False
Application.DisplayAlerts = True
Range("A6").Select
ActiveSheet.Paste
Range("A6").Select
Application.CutCopyMode = False
Range("F7").Select
ActiveCell.FormulaR1C1 = "=RC[-5]=R1C2"
Range("F7").Select
Selection.AutoFill Destination:=Range("F7:F45000")
Range("F7:F45000").Select
Range("A6:F6").Select
Range("F6").Activate
Selection.AutoFilter
Selection.AutoFilter Field:=6, Criteria1:="FALSE"
Rows("7:7").Select
Rows("7:45000").Select
Selection.Delete Shift:=xlUp
Selection.AutoFilter Field:=6, Criteria1:="TRUE"
Columns("F:F").Select
Selection.AutoFilter Field:=6
Selection.Delete Shift:=xlToLeft
Selection.AutoFilter
Range("A6").Select

End Sub


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
exit cell automatically after entering data Patrick Riley Excel Worksheet Functions 0 March 20th 08 03:23 PM
Execute vba code on cell exit Bill (Unique as my name) Excel Discussion (Misc queries) 2 May 24th 07 03:48 PM
Macro on exit cell nonshedders Excel Discussion (Misc queries) 1 April 12th 06 12:41 PM
Run Macro on cell exit Kelly Excel Programming 7 May 5th 04 09:42 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM


All times are GMT +1. The time now is 05:18 PM.

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

About Us

"It's about Microsoft Excel"