Excel 根据条件';日期';从表2到表1的值

Excel 根据条件';日期';从表2到表1的值,excel,excel-2007,excel-2003,worksheet-function,vba,Excel,Excel 2007,Excel 2003,Worksheet Function,Vba,使用Excel2007开发,但需要与2003兼容 问题: 工作簿有两页。第二页包含数据,A列至M列。C列的格式为日期值。并非所有行都包含列C中的值 工作表1有3'选项按钮(表单控件),标记为合同日期、生效日期和结束日期。选择合同日期时,需要使用条件过滤器查询第二页C列(此处包含日期)上的数据。。。如果日期

使用Excel2007开发,但需要与2003兼容

问题:

工作簿有两页。第二页包含数据,A列至M列。C列的格式为日期值。并非所有行都包含列C中的值

工作表1有3'选项按钮(表单控件),标记为合同日期、生效日期和结束日期。选择合同日期时,需要使用条件过滤器查询第二页C列(此处包含日期)上的数据。。。如果日期<今天的日期+14天。。。如果为true,则将该行的C列到M列复制到第1页,从单元格C13开始。继续,直到测试完所有数据行

如果选择了另一个“选项按钮”,则第一次查询的结果将替换为第二次查询的结果

这是我一直在编写的代码,但它不起作用

子选项按钮1\u单击()

Application.ScreenUpdating=False

模板\工作表=“数据\输入”

数据库\u sheet=“承运人”

myzerorange=“C”&ActiveWindow.RangeSelection.Row&“:”&“M”&ActiveWindow.RangeSelection.Row

mycompany=“C”&ActiveWindow.RangeSelection.Row

mydate=“D”&ActiveWindow.RangeSelection.Row

数据库\u sheet=ActiveSheet.Name

数据库记录=工作表(数据库工作表)。范围(“C2:C1000”) 第行计数=13

如果范围(mycompany)“,则

如果范围(mydate)“,则

"完"

如果结束

环路

Application.ScreenUpdating=True

端接头`


这似乎很容易做到,所以我猜你不太了解VBA。正如其他人所说,该网站不是关于构建你的应用程序;这是关于开发应用程序的人帮助其他开发应用程序的人

作为一名指导者,你应该能够将你的问题发布在gigs网站上,并在几个小时内完成你的项目。如果你想亲自或elance见面,或者如果你对虚拟现实没问题,可以试试craigslist


希望这有帮助。

这就是我对你的问题的想法。见评论。您需要将按钮单击绑定到CopyRowConditional

Sub CopyRowConditional()

Do

i = i + 1

    If Cells(i, 1).Value = "" Then Exit Do
                    ' this is to exit the loop when you reach an empty row

    If Cells(i, 1).Value = 10 Then ' this is where you put
                    ' the condition that triggers the copy
                    ' here I just put 10 as an example

        TargetRow = 4 ' this is where you need to determine how
                      ' you select the row that will receive the
                      ' data you're copying in the Target sheet
                      ' If you need to check for an empty row
                      ' you can add a Do ... Loop statement
                      ' that stops when the row is good

        For j = 1 To 14 ' this is where you loop in to the
                        'column of the Source sheet

        Sheets("Target").Cells(TargetRow, j).Value = Sheets("Source").Cells(i, j).Value
        ' this is the line that actually does the copying, cell by cell
        ' if you need to change the column index, just write .Cells(i, j+ n).value
        ' where n is any offeset you need


        Next j

    End If

Loop

End Sub

这里的问题需要更加集中。你要求同时做很多事情。这不是一个编写代码的网站。向我们展示您所做的工作。同时,请向我们展示一个示例,说明您的输入和输出,例如屏幕截图或格式正确的表格。如果需要获得固定宽度字体,请使用
code
格式。很少有人愿意阅读一份散文形式的电子表格描述。我一直在研究这个问题,但无法让它工作。。。我写的代码如下。好的。。。评论窗口不允许我发布代码。。。它报告了负面的聊天记录。只需发送你有合同日期过滤器的部分。如果我们让一个按钮工作,你就可以找出其他的。我把代码粘贴到评论窗口,它会报告一个负数字符。它不会添加评论。我做错了什么?代码超过600个字符。。。我已经通过编辑将代码添加到原始帖子中。好的,对你有用吗?只要看看它,您就需要考虑目标行在每次迭代中是如何变化的。可能您需要将Trownumber=Trownumber+1行移到测试for循环前几天条件的行之后。此外,在条件语句中,您可能希望通过“If Now-Cells(Srownumber,4)。Value<14 Then…”来简化此操作。另外,作为一种风格建议,以不同的格式设置变量可能更容易,特别是当其他人需要查看您的代码时。考虑SurnTo对StaveToWangSts. StrTrw。你连接了事件处理程序吗?为了进行调试,请按F8键一次执行一行,看看会发生什么。在第一行旁边放置一个断点以暂停代码,并为每个变量添加一个监视。另外,暂时删除屏幕更新行。Frenchie。。。谢谢你的帮助。一旦我理解了你指出的逻辑,我就真的成功了。我还让另外两个选项按钮工作。仍然不知道如何发布代码,因为这个网站的编辑器太糟糕了;一开始编程似乎几乎是不可能的,但它比你开始编程时看起来要容易得多。至于网站的编辑,一次只能写几行。祝你好运,继续前进!
   For Column = 3 To 13

   Sheets(template_sheet).Cells(Trownumber, Column).Value = >Sheets(Database_sheet).Cells(Srownumber, Column).Value

   Next Column
Sub CopyRowConditional()

Do

i = i + 1

    If Cells(i, 1).Value = "" Then Exit Do
                    ' this is to exit the loop when you reach an empty row

    If Cells(i, 1).Value = 10 Then ' this is where you put
                    ' the condition that triggers the copy
                    ' here I just put 10 as an example

        TargetRow = 4 ' this is where you need to determine how
                      ' you select the row that will receive the
                      ' data you're copying in the Target sheet
                      ' If you need to check for an empty row
                      ' you can add a Do ... Loop statement
                      ' that stops when the row is good

        For j = 1 To 14 ' this is where you loop in to the
                        'column of the Source sheet

        Sheets("Target").Cells(TargetRow, j).Value = Sheets("Source").Cells(i, j).Value
        ' this is the line that actually does the copying, cell by cell
        ' if you need to change the column index, just write .Cells(i, j+ n).value
        ' where n is any offeset you need


        Next j

    End If

Loop

End Sub