B
Brett Smith
I am programming a macro based on some information on the spreadsheet. As it
goes through, if it is missing certain information it will choose one format,
and if it has certain information which is in column C, it will choose
another format. Afterwards, it will take the information, spit it out into a
text file saved in RDF format. The problem is, I ran it and I got a "Compile
Error, For needed for Next". But the thing is, I have a For statement
towards the top. When I put a For there, it starts asking for Ifs to close
End Ifs or End Ifs to close Ifs. I'm confused but I thought my program would
have worked. Code is below.
Sub GetRows()
Dim FirstCell As Range, LastCell As Range
On Error Resume Next
Dim Firstrow As Long, Lastrow As Long
Dim Wordstring As String
Dim filePath As String
Dim I As Integer
Dim FName As Variant
Dim Rangecount As Integer
Dim intresult As Long
Dim NVariable As String
Dim MVariable As String
Dim AVariable As String
Dim AVARSTRING As String
Dim FVariable As String
Dim FVARSTRING As String
Dim EVariable As String
Dim EVARSTRING As String
Dim NandMVariable As String
Kill (filePath = ActiveWorkbook.Path & "\Seqfile.rdf")
I = 0
Tried = False
Tried2 = False
Wordstring = "$RDFILE 1" & vbCrLf & _
"$DATM " & Date & " " & Time & vbCrLf & _
"$RIREG 1" & vbCrLf & _
"$DTYPE BATCH:CHEMIST" & vbCrLf & _
"$DATUM REIDHAAJ" & vbCrLf & _
"$DTYPE BATCH:STRUCT_CMNT" & vbCrLf & _
"$DATUM [NUCLEIC ACID]" & vbCrLf & _
"$DTYPE STRUCTURE" & vbCrLf & _
"$DATUM $MFMT"
filePath = ActiveWorkbook.Path & "\Seqfile.rdf"
Open filePath For Output As #1
Print #1, Wordstring
Do
GetCell:
On Error Resume Next
Set FirstCell = Application.InputBox("Enter top left cell - ONE cell
only ", Type:=8)
On Error GoTo 0
If FirstCell Is Nothing Then
MsgBox "You pressed Cancel!" & IIf(Tried, "AGAIN! Good-bye!", "!")
If Tried Then Exit Sub
Tried = True
GoTo GetCell
Else
MsgBox FirstCell.Address
End If
Loop Until FirstCell.Count = 1
Firstrow = FirstCell.Row
Do
GetCell2:
On Error Resume Next
Set LastCell = Application.InputBox("Enter bottom right cell - ONE
cellonly ", Type:=8)
On Error GoTo 0
If LastCell Is Nothing Then
MsgBox "You pressed Cancel!" & IIf(Tried, "AGAIN! Good-Bye!", "!")
If Tried2 Then Exit Sub
Tried2 = True
GoTo GetCell2
Else
MsgBox LastCell.Address
End If
Loop Until LastCell.Count = 1
Lastrow = LastCell.Row
Firstrow = Int(Firstrow)
Lastrow = Int(Lastrow)
MsgBox Firstrow & " - " & Lastrow
Rangecount = Lastrow - Firstrow
MsgBox Rangecount & " records exported"
Range(Firstrow & ":" & Lastrow).Select
For I = Firstrow To Lastrow
If IsEmpty(Cells(I, "C").Value) Then
Dim G As Variant
Dim H As Variant
'Select Case IsEmpty(Cells(I, "G").Value) Or IsNull(Cells(I,
"G").Value) 'Cells(I, "G").Value = " "
If IsEmpty(Cells(I, "N").Value) Then
NVariable = Null
Else: NVariable = Cells(I, "N").Value
End If
If IsEmpty(Cells(I, "M").Value) Then
MVariable = Null
Else: MVariable = ""
End If
NandMVariable = NVariable + MVariable
If IsEmpty(NandMVariable) Then
NandMVariable = ""
Else
If IsEmpty(NVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & MVariable & char(59)"
Else
If IsEmpty(MVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & NVariable & char(59)"
Else
NandMVariable = " char(34) & $DATUM & char(34) & NVariable &
char(34)_char(34) & MVariable(char(59)"
End If
If IsEmpty(Cells(I, "A").Value) Then
AVariable = Null
Else: AVariable = Cells(I, "A").Value
End If
If IsEmpty(AVariable) Then
AVARSTRING = ""
Else
AVARSTRING = "char(34) & $DATUM siRNA for Gene target:char(34) &
char(38) & Avariable & char(38) & char(34) & char(59) & char(34) & char(44)"
End If
If IsEmpty(Cells(I, "F").Value) Then
FVariable = Null
Else: FVariable = Cells(I, "F").Value
End If
If IsEmpty(FVariable) Then
FVARSTRING = ""
Else
FVARSTRING = FVariable
End If
If IsEmpty(Cells(I, "E").Value) Then
EVariable = Null
Else: EVariable = Cells(I, "E").Value
End If
If IsEmpty(EVariable) Then
EVARSTRING = ""
Else: EVARSTRING = EVariable
End If
Print #1, vbCrLf; " -ISIS- 10310514382D" & vbCrLf & vbCrLf _
; " 0 0 0 0 0 0 0 0 0 0999 v2000" & vbCrLf _
; "M END" & vbCrLf _
; "$DTYPE BATCH:LAB_JOURNAL" & vbCrLf _
; NandMVariable & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_CODE" & vbCrLf _
; "$DATUM N" & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_DESC" & vbCrLf _
; "$DATUM Pool components: Pool1-1; Pool1-2; Pool1-3" &
vbCrLf _
; "$DTYPE BATCHRODUCER(1)RODUCER" & vbCrLf _
; "$DATUM " & Cells(I, "R").Value & ";", vbCrLf _
; "$DTYPE BATCHREP_DESCR" & vbCrLf _
; AVARSTRING & vbCrLf _
; FVARSTRING & vbCrLf _
; EVARSTRING & vbCrLf _
; "$DTYPE BATCH:GENERIC_NAME(1):GENERIC_NAME" & vbCrLf _
; "$DATUM " & Cells(I, "B").Value & ";"; vbCrLf _
; "$RIREG " & I - 2 & vbCrLf _
; "$DTYPE BATCH:CHEMIST" & vbCrLf _
; "$DATUM REIDHAAJ" & vbCrLf _
; "$DTYPE BATCH:STRUCT_CMNT" & vbCrLf _
; "$DATUM [NUCLEIC ACID]" & vbCrLf _
; "$DTYPE STRUCTURE" & vbCrLf _
; "$DATUM $MFMT"
'End Select
' Else
'Select Case IsEmpty(Cells(I, "H").Value) Or IsNull(Cells(I,
"H").Value) 'Cells(I, "H").Value = " "
If IsEmpty(Cells(I, "N").Value) Then
NVariable = Null
Else: NVariable = Cells(I, "N").Value
End If
If IsEmpty(Cells(I, "M").Value) Then
MVariable = Null
Else: MVariable = ""
End If
NandMVariable = NVariable + MVariable
If IsEmpty(NandMVariable) Then
NandMVariable = ""
Else
If IsEmpty(NVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & MVariable & char(59)"
Else
If IsEmpty(MVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & NVariable & char(59)"
Else
NandMVariable = " char(34) & $DATUM & char(34) & NVariable &
char(34)_char(34) & MVariable(char(59)"
End If
If IsEmpty(Cells(I, "A").Value) Then
AVariable = Null
Else: AVariable = Cells(I, "A").Value
End If
If IsEmpty(AVariable) Then
AVARSTRING = ""
Else
AVARSTRING = "char(34) & $DATUM siRNA for Gene target:char(34) &
char(38) & Avariable & char(38) & char(34) & char(59) & char(34) & char(44)"
End If
If IsEmpty(Cells(I, "F").Value) Then
FVariable = Null
Else: FVariable = Cells(I, "F").Value
End If
If IsEmpty(FVariable) Then
FVARSTRING = ""
Else
FVARSTRING = FVariable
End If
If IsEmpty(Cells(I, "E").Value) Then
EVariable = Null
Else: EVariable = Cells(I, "E").Value
End If
If IsEmpty(EVariable) Then
EVARSTRING = ""
Else: EVARSTRING = EVariable
End If
Print #1, vbCrLf; " -ISIS- 10310514382D" & vbCrLf & vbCrLf _
; " 0 0 0 0 0 0 0 0 0 0999 v2000" & vbCrLf _
; "M END" & vbCrLf _
; "$DTYPE BATCH:LAB_JOURNAL" & vbCrLf _
; NandMVariable & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_CODE" & vbCrLf _
; "$DATUM N" & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_DESC" & vbCrLf _
; "$DATUM Sense Strand: " & Cells(I, "C").Value; ";" & "
Antisense Strand:" & vbCrLf _
; Cells(I, "D").Value & ";", vbCrLf _
; "$DTYPE BATCHRODUCER(1)RODUCER" & vbCrLf _
; "$DATUM " & Cells(I, "R").Value & ";", vbCrLf _
; "$DTYPE BATCHREP_DESCR" & vbCrLf _
; AVARSTRING & vbCrLf _
; FVARSTRING & vbCrLf _
; EVARSTRING & vbCrLf _
; "$DTYPE BATCH:GENERIC_NAME(1):GENERIC_NAME" & vbCrLf _
; "$DATUM " & Cells(I, "B").Value & ";", vbCrLf _
; "$RIREG " & I - 2 & vbCrLf _
; "$DTYPE BATCH:CHEMIST" & vbCrLf _
; "$DATUM REIDHAAJ" & vbCrLf _
; "$DTYPE BATCH:STRUCT_CMNT" & vbCrLf _
; "$DATUM [NUCLEIC ACID]" & vbCrLf _
; "$DTYPE STRUCTURE" & vbCrLf _
; "$DATUM $MFMT"
End If
Next I
Close #1
End Sub
goes through, if it is missing certain information it will choose one format,
and if it has certain information which is in column C, it will choose
another format. Afterwards, it will take the information, spit it out into a
text file saved in RDF format. The problem is, I ran it and I got a "Compile
Error, For needed for Next". But the thing is, I have a For statement
towards the top. When I put a For there, it starts asking for Ifs to close
End Ifs or End Ifs to close Ifs. I'm confused but I thought my program would
have worked. Code is below.
Sub GetRows()
Dim FirstCell As Range, LastCell As Range
On Error Resume Next
Dim Firstrow As Long, Lastrow As Long
Dim Wordstring As String
Dim filePath As String
Dim I As Integer
Dim FName As Variant
Dim Rangecount As Integer
Dim intresult As Long
Dim NVariable As String
Dim MVariable As String
Dim AVariable As String
Dim AVARSTRING As String
Dim FVariable As String
Dim FVARSTRING As String
Dim EVariable As String
Dim EVARSTRING As String
Dim NandMVariable As String
Kill (filePath = ActiveWorkbook.Path & "\Seqfile.rdf")
I = 0
Tried = False
Tried2 = False
Wordstring = "$RDFILE 1" & vbCrLf & _
"$DATM " & Date & " " & Time & vbCrLf & _
"$RIREG 1" & vbCrLf & _
"$DTYPE BATCH:CHEMIST" & vbCrLf & _
"$DATUM REIDHAAJ" & vbCrLf & _
"$DTYPE BATCH:STRUCT_CMNT" & vbCrLf & _
"$DATUM [NUCLEIC ACID]" & vbCrLf & _
"$DTYPE STRUCTURE" & vbCrLf & _
"$DATUM $MFMT"
filePath = ActiveWorkbook.Path & "\Seqfile.rdf"
Open filePath For Output As #1
Print #1, Wordstring
Do
GetCell:
On Error Resume Next
Set FirstCell = Application.InputBox("Enter top left cell - ONE cell
only ", Type:=8)
On Error GoTo 0
If FirstCell Is Nothing Then
MsgBox "You pressed Cancel!" & IIf(Tried, "AGAIN! Good-bye!", "!")
If Tried Then Exit Sub
Tried = True
GoTo GetCell
Else
MsgBox FirstCell.Address
End If
Loop Until FirstCell.Count = 1
Firstrow = FirstCell.Row
Do
GetCell2:
On Error Resume Next
Set LastCell = Application.InputBox("Enter bottom right cell - ONE
cellonly ", Type:=8)
On Error GoTo 0
If LastCell Is Nothing Then
MsgBox "You pressed Cancel!" & IIf(Tried, "AGAIN! Good-Bye!", "!")
If Tried2 Then Exit Sub
Tried2 = True
GoTo GetCell2
Else
MsgBox LastCell.Address
End If
Loop Until LastCell.Count = 1
Lastrow = LastCell.Row
Firstrow = Int(Firstrow)
Lastrow = Int(Lastrow)
MsgBox Firstrow & " - " & Lastrow
Rangecount = Lastrow - Firstrow
MsgBox Rangecount & " records exported"
Range(Firstrow & ":" & Lastrow).Select
For I = Firstrow To Lastrow
If IsEmpty(Cells(I, "C").Value) Then
Dim G As Variant
Dim H As Variant
'Select Case IsEmpty(Cells(I, "G").Value) Or IsNull(Cells(I,
"G").Value) 'Cells(I, "G").Value = " "
If IsEmpty(Cells(I, "N").Value) Then
NVariable = Null
Else: NVariable = Cells(I, "N").Value
End If
If IsEmpty(Cells(I, "M").Value) Then
MVariable = Null
Else: MVariable = ""
End If
NandMVariable = NVariable + MVariable
If IsEmpty(NandMVariable) Then
NandMVariable = ""
Else
If IsEmpty(NVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & MVariable & char(59)"
Else
If IsEmpty(MVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & NVariable & char(59)"
Else
NandMVariable = " char(34) & $DATUM & char(34) & NVariable &
char(34)_char(34) & MVariable(char(59)"
End If
If IsEmpty(Cells(I, "A").Value) Then
AVariable = Null
Else: AVariable = Cells(I, "A").Value
End If
If IsEmpty(AVariable) Then
AVARSTRING = ""
Else
AVARSTRING = "char(34) & $DATUM siRNA for Gene target:char(34) &
char(38) & Avariable & char(38) & char(34) & char(59) & char(34) & char(44)"
End If
If IsEmpty(Cells(I, "F").Value) Then
FVariable = Null
Else: FVariable = Cells(I, "F").Value
End If
If IsEmpty(FVariable) Then
FVARSTRING = ""
Else
FVARSTRING = FVariable
End If
If IsEmpty(Cells(I, "E").Value) Then
EVariable = Null
Else: EVariable = Cells(I, "E").Value
End If
If IsEmpty(EVariable) Then
EVARSTRING = ""
Else: EVARSTRING = EVariable
End If
Print #1, vbCrLf; " -ISIS- 10310514382D" & vbCrLf & vbCrLf _
; " 0 0 0 0 0 0 0 0 0 0999 v2000" & vbCrLf _
; "M END" & vbCrLf _
; "$DTYPE BATCH:LAB_JOURNAL" & vbCrLf _
; NandMVariable & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_CODE" & vbCrLf _
; "$DATUM N" & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_DESC" & vbCrLf _
; "$DATUM Pool components: Pool1-1; Pool1-2; Pool1-3" &
vbCrLf _
; "$DTYPE BATCHRODUCER(1)RODUCER" & vbCrLf _
; "$DATUM " & Cells(I, "R").Value & ";", vbCrLf _
; "$DTYPE BATCHREP_DESCR" & vbCrLf _
; AVARSTRING & vbCrLf _
; FVARSTRING & vbCrLf _
; EVARSTRING & vbCrLf _
; "$DTYPE BATCH:GENERIC_NAME(1):GENERIC_NAME" & vbCrLf _
; "$DATUM " & Cells(I, "B").Value & ";"; vbCrLf _
; "$RIREG " & I - 2 & vbCrLf _
; "$DTYPE BATCH:CHEMIST" & vbCrLf _
; "$DATUM REIDHAAJ" & vbCrLf _
; "$DTYPE BATCH:STRUCT_CMNT" & vbCrLf _
; "$DATUM [NUCLEIC ACID]" & vbCrLf _
; "$DTYPE STRUCTURE" & vbCrLf _
; "$DATUM $MFMT"
'End Select
' Else
'Select Case IsEmpty(Cells(I, "H").Value) Or IsNull(Cells(I,
"H").Value) 'Cells(I, "H").Value = " "
If IsEmpty(Cells(I, "N").Value) Then
NVariable = Null
Else: NVariable = Cells(I, "N").Value
End If
If IsEmpty(Cells(I, "M").Value) Then
MVariable = Null
Else: MVariable = ""
End If
NandMVariable = NVariable + MVariable
If IsEmpty(NandMVariable) Then
NandMVariable = ""
Else
If IsEmpty(NVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & MVariable & char(59)"
Else
If IsEmpty(MVariable) Then
NandMVariable = "char(59) & ' ' & char(34) & $DATUM &
char(34) & NVariable & char(59)"
Else
NandMVariable = " char(34) & $DATUM & char(34) & NVariable &
char(34)_char(34) & MVariable(char(59)"
End If
If IsEmpty(Cells(I, "A").Value) Then
AVariable = Null
Else: AVariable = Cells(I, "A").Value
End If
If IsEmpty(AVariable) Then
AVARSTRING = ""
Else
AVARSTRING = "char(34) & $DATUM siRNA for Gene target:char(34) &
char(38) & Avariable & char(38) & char(34) & char(59) & char(34) & char(44)"
End If
If IsEmpty(Cells(I, "F").Value) Then
FVariable = Null
Else: FVariable = Cells(I, "F").Value
End If
If IsEmpty(FVariable) Then
FVARSTRING = ""
Else
FVARSTRING = FVariable
End If
If IsEmpty(Cells(I, "E").Value) Then
EVariable = Null
Else: EVariable = Cells(I, "E").Value
End If
If IsEmpty(EVariable) Then
EVARSTRING = ""
Else: EVARSTRING = EVariable
End If
Print #1, vbCrLf; " -ISIS- 10310514382D" & vbCrLf & vbCrLf _
; " 0 0 0 0 0 0 0 0 0 0999 v2000" & vbCrLf _
; "M END" & vbCrLf _
; "$DTYPE BATCH:LAB_JOURNAL" & vbCrLf _
; NandMVariable & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_CODE" & vbCrLf _
; "$DATUM N" & vbCrLf _
; "$DTYPE BATCH:LIN_STRUCT_DESC" & vbCrLf _
; "$DATUM Sense Strand: " & Cells(I, "C").Value; ";" & "
Antisense Strand:" & vbCrLf _
; Cells(I, "D").Value & ";", vbCrLf _
; "$DTYPE BATCHRODUCER(1)RODUCER" & vbCrLf _
; "$DATUM " & Cells(I, "R").Value & ";", vbCrLf _
; "$DTYPE BATCHREP_DESCR" & vbCrLf _
; AVARSTRING & vbCrLf _
; FVARSTRING & vbCrLf _
; EVARSTRING & vbCrLf _
; "$DTYPE BATCH:GENERIC_NAME(1):GENERIC_NAME" & vbCrLf _
; "$DATUM " & Cells(I, "B").Value & ";", vbCrLf _
; "$RIREG " & I - 2 & vbCrLf _
; "$DTYPE BATCH:CHEMIST" & vbCrLf _
; "$DATUM REIDHAAJ" & vbCrLf _
; "$DTYPE BATCH:STRUCT_CMNT" & vbCrLf _
; "$DATUM [NUCLEIC ACID]" & vbCrLf _
; "$DTYPE STRUCTURE" & vbCrLf _
; "$DATUM $MFMT"
End If
Next I
Close #1
End Sub