当前,我有某种形式的跟踪器表单,当填充表单中的字段时,它会发送到“合并”工作表,但是我需要根据条件(第P列)将它们发送到另一工作表。下面是当前代码。
Sub Transfer()
Set FormSht = Sheets("Tracker Form")
Set MasterSht = Sheets("Consolidated")
LR_form = FormSht.Cells(Rows.Count, "A").End(xlUp).Row
NR_master = MasterSht.Cells(Rows.Count, "A").End(xlUp).Row + 1
For RowX = 1 To LR_form
ColX = Application.WorksheetFunction.Match(FormSht.Cells(RowX, "A"), MasterSht.Rows(1), 0)
MasterSht.Cells(NR_master, ColX) = FormSht.Cells(RowX, "B")
Next RowX
End Sub
答案 0 :(得分:0)
喜欢吗?
Sub Transfer(sheet_name As String)
Set FormSht = Sheets("Tracker Form")
Set MasterSht = Sheets(sheet_name)
LR_form = FormSht.Cells(Rows.Count, "A").End(xlUp).Row
NR_master = MasterSht.Cells(Rows.Count, "A").End(xlUp).Row + 1
For RowX = 1 To LR_form
ColX = Application.WorksheetFunction.Match(FormSht.Cells(RowX, "A"), MasterSht.Rows(1), 0)
MasterSht.Cells(NR_master, ColX) = FormSht.Cells(RowX, "B")
Next RowX
End Sub
Sub cool_criteria()
'use your filter criterias here, if you have multiple try googeling "vba Select...Case"
If 2 > 1 Then
sheet_name = "Consolidated"
Else
sheet_name = "another sheet"
End If
Call Transfer(sheet_name)
End Sub
使用cool_criteria宏设置过滤器,然后这些过滤器将调用传输宏。