我有两张纸:
-预订从表单(car nr
、registration nr
、和)中car model
获取数据。和的值来自 dispo 通过 vlookup)
- dispo实际上只是一个日历,所有日期都在第一行和前四列中:、和.starting date
return date
registration nr
car model
car nr
registration nr
car model
today
我的程序必须将表单中的数据注册到“预订”(有效)中,然后从中找到“dispo”中对应于的单元格,starting date
并car nr
在其中放置一个“x”(实际上我想要一个“x " 在starting date
和之间的所有单元格中return date)
。
现在,car nr
固定为 1。这是我的代码:
Private Sub cmdajout_Click()
Dim dispo As Worksheet
Dim booking As Worksheet
Dim db As Range
Dim ligne As Integer
Dim l As Long
Dim c As Long
Dim maxc As Long
Dim maxl As Long
Set dispo = ActiveWorkbook.Sheets("Dispo")
Set booking = ActiveWorkbook.Sheets("booking")
Set db = dispo.Range("A2:C35")
vehicule = 1
' find the first empty row
If Sheets("booking").Range("A2").Value = "" Then
ligne = 2
Else:
ligne = Sheets("booking").Range("A1").End(xlDown).Row + 1
End If
' copy the data from the form to "booking" and get by vlookup the missing data
booking.Range("A" & ligne).Value = vehicule
imma = Application.WorksheetFunction.VLookup(booking.Range("A" & ligne), db, 2, False)
booking.Range("B" & ligne).Value = imma
model = Application.WorksheetFunction.VLookup(booking.Range("A" & ligne), db, 3, False)
booking.Range("C" & ligne).Value = model
booking.Range("D" & ligne).Value = Format(txtdepart, "short date")
booking.Range("E" & ligne).Value = Format(txtfin, "short date")
booking.Range("F" & ligne).Value = txtclient
booking.Range("G" & ligne).Value = txtlocation
Unload Me
' book the date in the calendar "dispo"
dispo.Select
maxc = dispo.Range("A1").End(xlToRight).Column
maxl = dispo.Range("A1").End(xlDown).Row
For c = 5 To maxc
If dispo.Cells(1, c).Value = txtdepart Then 'it's here that i don't understant ... if i write = "05-01-2013" it finds it, but if i write = txtdepart (wich is where in the form i entered the date), it doesnt find
For l = 2 To maxl
If dispo.Range("A" & l).Value = vehicule Then 'same proble here ... it finds if i enter ="1" but not if i write = vehicule
dispo.Cells(l, c).Value = "x"
Else:
End If
Next l
Else:
End If
Next c
End Sub
- 有人帮我解决我的问题吗?
- 谁能给我代码,让它在
starting date
和之间的所有单元格中放置一个“x”return date
?