I have just begun using macros in Excel, so I know nothing about it. This is the macro I'm using, which creates files named after the cells in the A column. The cells themselves are filled by the content of other cells from the B to the F columns.
Sub Titles()
Dim xSh As Worksheet
Application.ScreenUpdating = False
For Each xSh In Worksheets
xSh.Select
Call RunCode
Next
Application.ScreenUpdating = True
End Sub
Sub RunCode()
'your code here
Const forReading = 1, forAppending = 3, fsoForWriting = 2
Dim fs, objTextStream, sText As String
Dim lLastRow As Long, lRowLoop As Long, lLastCol As Long, lColLoop As Long
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
For lRowLoop = 1 To lLastRow
Set fs = CreateObject("Scripting.FileSystemObject")
Set objTextStream = fs.opentextfile("C:\Temp\Titles\" & Cells(lRowLoop, 1) & ".title", fsoForWriting, True)
sText = ""
For lColLoop = 1 To 7
sText = sText & Cells(lRowLoop, lColLoop) & Chr(10) & Chr(10)
Next lColLoop
objTextStream.writeline (Left(sText, Len(sText) - 1))
objTextStream.Close
Set objTextStream = Nothing
Set fs = Nothing
Next lRowLoop
End Sub
The macro is working just fine, but I would like to make one adjustment, which is to not create a file if the correspondent cell in the F column is empty, (B to E are always filled).
I hope I explained myself correctly.
Thank you for your help.
If Not IsEmpty(Cells(lRowLoop, "F").Value) Then
...