Case without select case error compile error

Case without select case error compile error



Hello I keep getting a compile error on this segment of my code and can't find what i'm missing:


Case 5 ' Base oil specification changes?
' search datatbl for next empty row
rw = data.Range.Rows.Count
If rw = 2 Then
If data.Range(rw, 1).Value = "" Then
rw = 1
Else
data.Range(rw, 1).ListObject.ListRows.Add alwaysinsert:=True
End If
End If
'populate the data table
With data
.Range(rw, 1).Offset(1) = Date
.Range(rw, 2).Offset(1) = "A"
.Range(rw, 3).Offset(1) = "Marketing"
.Range(rw, 4).Offset(1) = Me.Controls("lblA" & i).Caption
End With
If Me.Controls("OptA" & i & "Y") = True Then
With data
.Range(rw, 5).Offset(1) = Me.Controls("OptA" & i & "Y").Caption
.Range(rw, 6).Offset(1) = Me.Controls("txtA" & i).Value
.Range(rw, 7).Offset(1) = "PLANT"
End With
'add data to summary table
r = summary.Range.Rows.Count
If r = 2 Then
If summary.Range(r, 1).Value = "" Then
r = 1
Else
summary.Range(r, 1).ListObject.ListRows.Add alwaysinsert:=True
End If
End If
With summary
.Range(r, 1).Offset(1) = Me.Controls("lblA" & i).Caption
.Range(r, 2).Offset(1) = Me.Controls("OptA" & i & "Y").Caption
.Range(r, 3).Offset(1) = Me.Controls("txtA" & i).Value
.Range(r, 4).Offset(1) = "PLANT"
End With
ElseIf Me.Controls("OptA" & i & "N") = True Then
data.Range(rw, 5).Offset(1) = Me.Controls("OptA" & i & "N").Caption
End If






summary.Range(r, 1).ListObject.ListRows.Add alwaysinsert:=True doesn't look right. Maybe ...ListObjects(1)...

– user4039065
Sep 16 '18 at 23:44



summary.Range(r, 1).ListObject.ListRows.Add alwaysinsert:=True


...ListObjects(1)...






That rather large snippet seems to only include a fraction of the actual full-length procedure. I would warmly recommend extracting each Case block into its own Private Sub procedure, to significantly reduce the line count, reduce the nesting, reduce the cognitive/mental load, and reduce the chances of introducing a compile error by losing track of what block starts/ends where. Also, consistent indentation usually helps preventing such errors.

– Mathieu Guindon
Sep 16 '18 at 23:55


Case


Private Sub




1 Answer
1



You need to add Select Case in order to use the Case method followed by the object that is being analyzed. Once complete, end with End Select.


Select Case


Case


End Select



Generic example below showing how to implement the basics of Select Case where the object to be analyzed is Range("A1")


Select Case


Range("A1")


Select Case Range("A1")
Case 5
'Do something if case is met
Case Else
'Do something is case is Else
End Select



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế