Thread
:
IF Statement in Macro
View Single Post
#
2
Posted to microsoft.public.excel.programming
Don Guillett
external usenet poster
Posts: 10,124
IF Statement in Macro
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
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett