Hoi allemaal,
Van dit forum heb ik een macro gehaald en zelf ge-edit. Alles werkt, maar het lukt me niet om in de macro een werkende vlookup te bouwen (zie 4de regel van onderen in de macro). Het rare is dat de formule wel netjes in excel komt te staan, maar vervolgens niet de waarde geeft dit hij moet geven. De formule geeft de foutmedling #naam?. Echter als ik de geplaatste formule in excel aanklik en op enter druk doet hij het wel. Dus de formule die de macro plaatst is goed, maar hij voert hem niet gelijk uit? Iemand enig idee wat er aan de hand is?
Macro:
Private Sub UserForm_Initialize()
Datum.Value = ""
Naam.Value = ""
Langhaar.Value = ""
Product1.Value = ""
Product2.Value = ""
Product3.Value = ""
Product4.Value = ""
Product5.Value = ""
Product6.Value = ""
Product7.Value = ""
Product8.Value = ""
Product9.Value = ""
Product10.Value = ""
Datum.SetFocus
End Sub
Private Sub cmdOK_Click()
Dim x As Long, y As Long, z As Long
x = Cells(Rows.Count, "A").End(xlUp).Row + 1 '1e lege cel in A
y = Cells(Rows.Count, "B").End(xlUp).Row + 1 '1e lege cel in B
z = Cells(Rows.Count, "C").End(xlUp).Row + 1 '1e lege cel in C
ActiveWorkbook.Sheets("Invoer").Activate
Range("B5").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Offset(0, 0) = Format(Datum.Value, "dd-mm-yy")
ActiveCell.Offset(0, 1) = Naam.Value
ActiveCell.Offset(0, 2) = Langhaar.Value
ActiveCell.Offset(0, 4) = Product1.Value
ActiveCell.Offset(0, 5) = Product2.Value
ActiveCell.Offset(0, 6) = Product3.Value
ActiveCell.Offset(0, 7) = Product4.Value
ActiveCell.Offset(0, 8) = Product5.Value
ActiveCell.Offset(0, 9) = Product6.Value
ActiveCell.Offset(0, 10) = Product7.Value
ActiveCell.Offset(0, 11) = Product8.Value
ActiveCell.Offset(0, 12) = Product9.Value
ActiveCell.Offset(0, 13) = Product10.Value
Range("E" & z).Formula = "=IF(RC[-1]=""kort haar"",VLOOKUP(RC[+1],Prijslijst!A:B,2,False),"""")"
Range("A" & x).Formula = "=MONTH(RC[1])"
Range("A1").Select
End Sub
Van dit forum heb ik een macro gehaald en zelf ge-edit. Alles werkt, maar het lukt me niet om in de macro een werkende vlookup te bouwen (zie 4de regel van onderen in de macro). Het rare is dat de formule wel netjes in excel komt te staan, maar vervolgens niet de waarde geeft dit hij moet geven. De formule geeft de foutmedling #naam?. Echter als ik de geplaatste formule in excel aanklik en op enter druk doet hij het wel. Dus de formule die de macro plaatst is goed, maar hij voert hem niet gelijk uit? Iemand enig idee wat er aan de hand is?
Macro:
Private Sub UserForm_Initialize()
Datum.Value = ""
Naam.Value = ""
Langhaar.Value = ""
Product1.Value = ""
Product2.Value = ""
Product3.Value = ""
Product4.Value = ""
Product5.Value = ""
Product6.Value = ""
Product7.Value = ""
Product8.Value = ""
Product9.Value = ""
Product10.Value = ""
Datum.SetFocus
End Sub
Private Sub cmdOK_Click()
Dim x As Long, y As Long, z As Long
x = Cells(Rows.Count, "A").End(xlUp).Row + 1 '1e lege cel in A
y = Cells(Rows.Count, "B").End(xlUp).Row + 1 '1e lege cel in B
z = Cells(Rows.Count, "C").End(xlUp).Row + 1 '1e lege cel in C
ActiveWorkbook.Sheets("Invoer").Activate
Range("B5").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Offset(0, 0) = Format(Datum.Value, "dd-mm-yy")
ActiveCell.Offset(0, 1) = Naam.Value
ActiveCell.Offset(0, 2) = Langhaar.Value
ActiveCell.Offset(0, 4) = Product1.Value
ActiveCell.Offset(0, 5) = Product2.Value
ActiveCell.Offset(0, 6) = Product3.Value
ActiveCell.Offset(0, 7) = Product4.Value
ActiveCell.Offset(0, 8) = Product5.Value
ActiveCell.Offset(0, 9) = Product6.Value
ActiveCell.Offset(0, 10) = Product7.Value
ActiveCell.Offset(0, 11) = Product8.Value
ActiveCell.Offset(0, 12) = Product9.Value
ActiveCell.Offset(0, 13) = Product10.Value
Range("E" & z).Formula = "=IF(RC[-1]=""kort haar"",VLOOKUP(RC[+1],Prijslijst!A:B,2,False),"""")"
Range("A" & x).Formula = "=MONTH(RC[1])"
Range("A1").Select
End Sub