我有一个系统,可以将代码输入电子表格中的单元格。它通过使用Vlookup来确定它的日期。如果你查看下面的代码,那么这个Vlookup就是nput。
我想要它做的是向下移动每个数量的单元格,该数量将是名为DayAmount的组合框值中的数量。我需要输入什么来查看下一个单元格?
例如,如果1月5日在A24,我希望它也在1月6日和7日输入相同的代码,Vlookup知道它是A25和A26。
Private Sub Submitplan_Click()
' This searches for the selected engineer
Dim EngineerFound As Range
Dim Front As Worksheet
Dim wb As Workbook
Dim area As Worksheet
Set wb = ThisWorkbook
Dim tabchange As String
Set Front = wb.Worksheets("Front")
x = Front.Cells(Front.Rows.Count, "F").End(xlUp).Row
With Front.Range("F8:F" & x)
Set EngineerFound = .Find(Engbox.Value, LookIn:=xlValues)
End With
EngRow = EngineerFound.Row
'This is the section which enters the data into the right date
tabchange = ("Area") & Front.Range("B8")
Set area = wb.Worksheets(tabchange)
y = WorksheetFunction.VLookup(CLng(CDate(Datebox.Value)), area.Range("A:B"), 2, 0)
nPut = WorksheetFunction.VLookup(Key, area.Range("A:B"), 2, 0) &
Hoursbox.Value
z = area.Range("C:C").Find(Engbox.Value).Row
If area.Cells(z, y).Value = " B/H" Then
area.Cells(z, y).Value = nPut & " " & "B/H"
ElseIf area.Cells(z, y).Value = " WK" Then
area.Cells(z, y).Value = nPut & " " & "WK"
Else: area.Cells(z, y).Value = nPut
End If
' If DayAmount <> "" Then
'End If
Call Update
Unload Me
End Sub
答案 0 :(得分:1)
如果我正确读取此内容,您在组合框中有一个值(将说明 DayAmount ),该值将被分配,直到满足该值。
Dim i as Long, j as Long, k as Long
i = ActiveCell.Row
j = DayAmount
k = 1
If j > 1 Then
Do until k = j-1
Cells(k+1,1).Value = Cells(i,1)>Value
k = i + k
Loop
End If
或者您可以使用filldown或.value匹配,当您输入到目标单元格的行时,您可以使用:
Dim i as Long, j as Long
i = ActiveCell.Row
j = DayAmount
Range(Cells(i,1),Cells(i+j,1)).Value = "" 'input here
请注意任意的activecell和第1列用法,因为我不确定这对你来说究竟在哪里。
具体而言,关于nPut的使用,您可以使用offset来帮助,例如:
Range(nPut, nPut.Offset(DayAmount,0)) = WorksheetFunction.VLookup(Key, area.Range("A:B"), 2, 0) & Hoursbox.Value
请注意,我还没有对后者进行过测试,而且它已经脱离了我的头脑。