Hi Everyone

So I need assistance with finishing this code. The problem here is that the code is not counting the correct number of rows that contain values.

if you refer to the code below, there are 12 columns of interest. the start at row 12 and the column changes. The columns start never changes though. (e.g. 1st column of interest starts at F21, 2nd column at M21 etc). the

end of the column range varies. the columns will either have a value such as "1000.00,1450.000", "pline" or will be empty, but the empty cells were created from a formula. In other words, the range is derived from a formula, such as if( x = y, then "1000.00,1450.00", if(x=z, "pline", "")). The code should only pick if the count for th rows that contain "1000.00,1450.00" or "pline".

Thank you, Please let me know if you need further explanation.

*note: the first 3 loops, z = 1,2,3, may be different from the rest because I've been trying to figure it out, and I still am.

```
Sub Script_File_Export_3()
Dim myfile As String, rng As Range, cellvalue As String, i As Integer, j As Integer
Const basefilename As String = "HGL_"
Dim x As Integer
Dim z As Long
Const outputpath As String = "C:\Users\mbecerra\Documents\Batch File Folder\HGL\3) HGL Script Files\"
Set rng = Selection
Range("a1").Select
Range("f21", Range("f21").End(xlDown)).Select
'n = Worksheets("Sheet1").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).count
' counts number of cells that i need but misses one
'x = n + 1
' this one accounts for that missing one
For z = 1 To 12
Open outputpath & basefilename & z & ".scr" For Output As #1
If z = 1 Then
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 2 Then
For i = 1 To rng.Rows.SpecialCells(xlCellTypeVisible).count + 1
'For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 3 Then
Range("t21", Range("t21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 4 Then
Range("aa21", Range("aa21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 5 Then
Range("ah21", Range("ah21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 6 Then
Range("ao21", Range("ao21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 7 Then
Range("av21", Range("av21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 8 Then
Range("bc21", Range("bc21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 9 Then
Range("bj21", Range("bj21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 10 Then
Range("bq21", Range("bq21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 11 Then
Range("bx21", Range("bx21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
If z = 12 Then
Range("cf21", Range("cf21").End(xlDown)).Select
For i = 1 To rng.Rows.count
cellvalue = ""
cellvalue = rng.Cells(i, 1).Value
Print #1, cellvalue
Next i
Close #1
Else
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next
End Sub
```

Display More