Dialog

I

Ivica Lopar

In sheet1 I have some values.With this macro I wont to add new values in
sheet1 but i have an error.Can somebody help me.

Sub Dodaj()
Dim Pod(6)
Dim ind As Integer

With DialogSheets("DialogProdaja")
ind = .DropDowns(1).ListIndex
Pod(1) = .EditBoxes(1).Text
Pod(2) = .EditBoxes(2).Text
Pod(3) = .DropDowns(1).List(ind)
Pod(4) = .EditBoxes(3).Text
Pod(5) = .EditBoxes(4).Text
Pod(6) = .EditBoxes(5).Text
End With
If IsDate(Pod(1)) And IsNumeric(Pod(4)) And IsNumeric(Pod(5)) And
IsNumeric(Pod(6)) Then
With Worksheets("Prodaja")
NoviRed = .Cells(1, 1).CurrentRegion.Rows.Count + 1
For i = 1 To 6
..Cells(NoviRed, i).Value = Pod(i)
Next i
..Cells(NoviRed - 1, 7).AutoFill Destination:=Range(.Cells(NoviRed - 1, 7),
..Cells(NoviRed, 7)), Type:=xlFillDefault
..Cells(NoviRed, 1).NumberFormat = "dd-mm-yyyy."
..Cells(NoviRed, 6).Value = Pod(6) / 100
..Cells(NoviRed, 6).NumberFormat = "0%"
End With
Else
MsgBox prompt:="Podaci nisu ispravno uneseni", Buttons:=vbExclamation
End If

End Sub


regards
lopar
 
P

Philip

Hi,

aren't all lines like this:

...Cells(NoviRed, ...

supposed to be like this:

..Cells(NoviRed, ...

In the With block, you have 2 full-stops (..) - I think it should always be
only one. hence:

Dim Pod(6)
Dim ind As Integer

With DialogSheets("DialogProdaja")
ind = .DropDowns(1).ListIndex
Pod(1) = .EditBoxes(1).Text
Pod(2) = .EditBoxes(2).Text
Pod(3) = .DropDowns(1).List(ind)
Pod(4) = .EditBoxes(3).Text
Pod(5) = .EditBoxes(4).Text
Pod(6) = .EditBoxes(5).Text
End With
If IsDate(Pod(1)) And IsNumeric(Pod(4)) And _
IsNumeric(Pod(5)) _
And IsNumeric(Pod(6)) Then
With Worksheets("Prodaja")
NoviRed = .Cells(1, 1).CurrentRegion.Rows.Count + 1
For i = 1 To 6
.Cells(NoviRed, i).Value = Pod(i)
Next i
.Cells(NoviRed - 1, 7).AutoFill _
Destination:=Range(.Cells(NoviRed - 1, 7), _
.Cells(NoviRed, 7)), Type:=xlFillDefault
.Cells(NoviRed, 1).NumberFormat = "dd-mm-yyyy."
.Cells(NoviRed, 6).Value = Pod(6) / 100
.Cells(NoviRed, 6).NumberFormat = "0%"
End With
Else
MsgBox prompt:="Podaci nisu ispravno uneseni", Buttons:=vbExclamation
End If

<<<< END CODE <<<<<

If not that, then tell us what line the error happens on, and what the error
is.

HTH

Philip
 
I

Ivica Lopar

Error Variable not defined (Novi red)

NoviRed = .Cells(1, 1).CurrentRegion.Rows.Count + 1
 
I

Ivica Lopar

Error Variable not defined ( red).same error in this code.

red = .DropDowns(1).ListIndex + 1

Sub OdabirKnjige()
Dim cijena As Integer

With DialogSheets("DialogProdaja")
red = .DropDowns(1).ListIndex + 1
cijena = Worksheets("Knjige").Cells(red, 2).Value
..EditBoxes(4).Text = cijena
..EditBoxes(3).Text = 1
..EditBoxes(5).Text = 0
..Labels(8).Text = cijena
..Spinners(1).Value = 1
..Spinners(2).Value = 0
End With
 
P

Philip

Ah !

Sorry, I should have checked for that too :)

try this code (I have added new 'Dim' statements for NoviRed and i)
Sub Dodaj()
Dim Pod(6)
Dim ind As Integer
Dim NoviRed As Long, i As Integer

With DialogSheets("DialogProdaja")
ind = .DropDowns(1).ListIndex
Pod(1) = .EditBoxes(1).Text
Pod(2) = .EditBoxes(2).Text
Pod(3) = .DropDowns(1).List(ind)
Pod(4) = .EditBoxes(3).Text
Pod(5) = .EditBoxes(4).Text
Pod(6) = .EditBoxes(5).Text
End With
If IsDate(Pod(1)) And IsNumeric(Pod(4)) And _
IsNumeric(Pod(5)) _
And IsNumeric(Pod(6)) Then
With Worksheets("Prodaja")
NoviRed = .Cells(1, 1).CurrentRegion.Rows.Count + 1
For i = 1 To 6
.Cells(NoviRed, i).Value = Pod(i)
Next i
.Cells(NoviRed - 1, 7).AutoFill _
Destination:=Range(.Cells(NoviRed - 1, 7), _
.Cells(NoviRed, 7)), Type:=xlFillDefault
.Cells(NoviRed, 1).NumberFormat = "dd-mm-yyyy."
.Cells(NoviRed, 6).Value = Pod(6) / 100
.Cells(NoviRed, 6).NumberFormat = "0%"
End With
Else
MsgBox prompt:="Podaci nisu ispravno uneseni", Buttons:=vbExclamation
End If

End Sub
<<< END CODE <<<

Whenever you see an error like that, always check that the highlighted
variable or statement has a DIM for it.... either locally in the procedure,
or in the module.

HTH

Philip
 
I

Ivica Lopar

thanks for help it is working now

regards
lopar

Philip said:
Ah !

Sorry, I should have checked for that too :)

try this code (I have added new 'Dim' statements for NoviRed and i)

Sub Dodaj()
Dim Pod(6)
Dim ind As Integer
Dim NoviRed As Long, i As Integer

With DialogSheets("DialogProdaja")
ind = .DropDowns(1).ListIndex
Pod(1) = .EditBoxes(1).Text
Pod(2) = .EditBoxes(2).Text
Pod(3) = .DropDowns(1).List(ind)
Pod(4) = .EditBoxes(3).Text
Pod(5) = .EditBoxes(4).Text
Pod(6) = .EditBoxes(5).Text
End With
If IsDate(Pod(1)) And IsNumeric(Pod(4)) And _
IsNumeric(Pod(5)) _
And IsNumeric(Pod(6)) Then
With Worksheets("Prodaja")
NoviRed = .Cells(1, 1).CurrentRegion.Rows.Count + 1
For i = 1 To 6
.Cells(NoviRed, i).Value = Pod(i)
Next i
.Cells(NoviRed - 1, 7).AutoFill _
Destination:=Range(.Cells(NoviRed - 1, 7), _
.Cells(NoviRed, 7)), Type:=xlFillDefault
.Cells(NoviRed, 1).NumberFormat = "dd-mm-yyyy."
.Cells(NoviRed, 6).Value = Pod(6) / 100
.Cells(NoviRed, 6).NumberFormat = "0%"
End With
Else
MsgBox prompt:="Podaci nisu ispravno uneseni", Buttons:=vbExclamation
End If

End Sub
<<< END CODE <<<

Whenever you see an error like that, always check that the highlighted
variable or statement has a DIM for it.... either locally in the
procedure,
or in the module.

HTH

Philip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top