![]() |
IF Statement in Macro
I have a macro that opens workbooks. The paths for the workbooks are
contained in various cells, say Cell A1 contains the path for Workbook1, Cell A2 contains the path to Workbook2, and Cell A3 contains the path to Workbook3, and so on, and the macro opens the files that are specified in each of the cells. However, some of the cells on which the macro operates are blank, which creates an error. Im trying to use an IF statement to have the macro skip over the blank cells, and thus avoid an error, but have had no luck so far. My co-worker suggested using the following code: If Range("A1").Value = "" then Goto 2 [Code to open file contained in Cell A2] End IF 1: [Macto to open file contained in A1] End Sub However, this code generates the following error :"End if without block IF" Any advice you could give me on overcoming the problem would be greatly appreciated? Magnivy |
IF Statement in Macro
Don,
Got It! Thanks a lot for your help! Magnivy "Don Guillett" wrote: try this instead where the list is c:\yourdirectory\yourfile blank c:\yourdirectory\yourfile1 blank Sub openworkbooksinlist() On Error Resume Next For Each c In Range("a1:a4") Workbooks.Open Filename:=c & ".xls" Next c End Sub -- Don Guillett SalesAid Software "Magnivy" wrote in message ... I have a macro that opens workbooks. The paths for the workbooks are contained in various cells, say Cell A1 contains the path for Workbook1, Cell A2 contains the path to Workbook2, and Cell A3 contains the path to Workbook3, and so on, and the macro opens the files that are specified in each of the cells. However, some of the cells on which the macro operates are blank, which creates an error. I'm trying to use an IF statement to have the macro skip over the blank cells, and thus avoid an error, but have had no luck so far. My co-worker suggested using the following code: If Range("A1").Value = "" then Goto 2 [Code to open file contained in Cell A2] End IF 1: [Macto to open file contained in A1] End Sub However, this code generates the following error :"End if without block IF" Any advice you could give me on overcoming the problem would be greatly appreciated? Magnivy |
IF Statement in Macro
glad to help
-- Don Guillett SalesAid Software "Magnivy" wrote in message ... Don, Got It! Thanks a lot for your help! Magnivy "Don Guillett" wrote: try this instead where the list is c:\yourdirectory\yourfile blank c:\yourdirectory\yourfile1 blank Sub openworkbooksinlist() On Error Resume Next For Each c In Range("a1:a4") Workbooks.Open Filename:=c & ".xls" Next c End Sub -- Don Guillett SalesAid Software "Magnivy" wrote in message ... I have a macro that opens workbooks. The paths for the workbooks are contained in various cells, say Cell A1 contains the path for Workbook1, Cell A2 contains the path to Workbook2, and Cell A3 contains the path to Workbook3, and so on, and the macro opens the files that are specified in each of the cells. However, some of the cells on which the macro operates are blank, which creates an error. I'm trying to use an IF statement to have the macro skip over the blank cells, and thus avoid an error, but have had no luck so far. My co-worker suggested using the following code: If Range("A1").Value = "" then Goto 2 [Code to open file contained in Cell A2] End IF 1: [Macto to open file contained in A1] End Sub However, this code generates the following error :"End if without block IF" Any advice you could give me on overcoming the problem would be greatly appreciated? Magnivy |
All times are GMT +1. The time now is 03:45 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com