Urgent! Error in "Else without If"

aribfaishal

New Member
Joined
Jan 26, 2015
Messages
3
anyone can help me to solve this code? it always stuck "Else Without If".
for my homework :(
this is the code (some code like MsgBox using indonesian language because i'm from indonesia :D ):

Private Sub CmbInput_Click()
Set info = Worksheets(CekHarga)
If info.Range("C3").Value = "" Then pesan = MsgBox("PERHATIAN!!!" & vbCrLf & "Kolom nama/kode barang masih kosong!", vbOKOnly + vbCritical, "INPUT GAGAL")
Call Range("C3").Select
Else info.Range("C3").Value <> "" Then pesan = MsgBox("Masukkan data sekarang?", vbYesNo + vbInformation, "Informasi Data")
If pesan = vbYes Then
Set dbs = Worksheets("Dafter Pesanan")
linenext = dbs.Cells(Rows.Count, “A”).End(xlUp).Offset(2, 0).Row
dbs.Cells(linenext, 1).Value = Range("C3").Value
End If
End Sub


The code Stuck at :
Else info.Range("C3").Value <> "" Then pesan = MsgBox("Masukkan data sekarang?", vbYesNo + vbInformation, "Informasi Data")


for everybody, thanks before :)
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Welcome to MrExcel. Probably the way you have written code is causing error.

Untested:
Code:
Private Sub CmbInput_Click()

Set info = Worksheets(CekHarga)
If info.Range("C3").Value = "" Then
    pesan = MsgBox("PERHATIAN!!!" & vbCrLf & "Kolom nama/kode barang masih kosong!", vbOKOnly + vbCritical, "INPUT GAGAL")
    Call Range("C3").Select
Else
    pesan = MsgBox("Masukkan data sekarang?", vbYesNo + vbInformation, "Informasi Data")
End If

If pesan = vbYes Then
    Set dbs = Worksheets("Dafter Pesanan")
    linenext = dbs.Cells(Rows.Count, "A").End(xlUp).Offset(2, 0).Row
    dbs.Cells(linenext, 1).Value = Range("C3").Value
End If

End Sub
 
Upvote 0
Code:
Private Sub CmbInput_Click()
Set info = Worksheets(CekHarga)
If info.Range("C3").Value = "" Then
 pesan = MsgBox("PERHATIAN!!!" & vbCrLf & "Kolom nama/kode barang masih kosong!", vbOKOnly + vbCritical, "INPUT GAGAL")
 Call Range("C3").Select
ElseIf info.Range("C3").Value <> "" Then pesan = MsgBox("Masukkan data sekarang?", vbYesNo + vbInformation, "Informasi Data")
End If
If pesan = vbYes Then
Set dbs = Worksheets("Dafter Pesanan")
linenext = dbs.Cells(Rows.Count, “A”).End(xlUp).Offset(2, 0).Row
dbs.Cells(linenext, 1).Value = Range("C3").Value
End If

End Sub
 
Upvote 0
did it! with this code :

Private Sub CmbInput_Click()
Set info = Worksheets("CekHarga")
If info.Range("C4").Value = "" Then
pesan = MsgBox("WTF???" & vbCrLf & "Kolom nama/kode barang masih kosong!", vbOKOnly + vbCritical, "INPUT GAGAL")
Call Range("C4").Select
ElseIf info.Range("C4").Value <> "" Then pesan = MsgBox("Masukkan data sekarang?", vbYesNo + vbInformation, "Informasi Data")
End If
If pesan = vbYes Then
Set dbs = Worksheets("Dafter Pesanan")
linenext = dbs.Cells(Rows.Count, “A”).End(xlUp).Offset(1, 0).Row
dbs.Cells(linenext, 1).Value = Range("C4").Value
End If


End Sub

but i got error again, error message "Run time error '1004'", error from this code :
linenext = dbs.Cells(Rows.Count, “A”).End(xlUp).Offset(1, 0).Row

what must i do?
 
Upvote 0
Your double quotes don't look right.
linenext = dbs.Cells(Rows.Count, A).End(xlUp).Offset(1, 0).Row

Try instead:
linenext = dbs.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top