编辑预先存在的宏以添加日期范围功能

时间:2017-04-24 20:05:03

标签: excel vba excel-vba

我是宏的新手,我的任务是编辑我的前任写的一个。如果列A匹配另一个工作表中的命名单元格(可更改日期),则当前宏从一个工作表中选择大部分数据。他们要求我对其进行编辑,以便用户可以更改两个日期字段,并且宏将复制并过去第一列中日期等于2或输入的两个日期之间的行。我尝试过一些东西,但要么忽略了我的编辑,要么崩溃了宏。我很感激建议,特别是因为我是新手。目前的代码如下:

  Sub Macro1()
'
' Macro1 Macro
'

'
    Application.Goto Reference:="Data_Entry"

    Selection.Copy
    Application.Goto Reference:="EndDB"
    Selection.End(xlUp).Select
    Range("A4").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=True
    Range("C8").Select
End Sub
Sub Get_Data()
Dim x As Integer
Dim y As Integer
Dim key As String

'
Application.ScreenUpdating = False
clear
Application.Goto Reference:="keyname"
 key = Range("keyname").Value


    For x = 2 To 10000
Application.Goto Reference:="startme"
If Range("c" & x) = key Then


    Range("a" & x & ":P" & x).Select
    Selection.Copy


Application.Goto Reference:="query"
    Selection.End(xlUp).Select
  y = ActiveCell.Row + 1
      Range("a" & y).Select



    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False

End If
Next x

Application.Goto Reference:="keyname"
End Sub

Sub Get_Data_date()
Dim x As Integer
Dim y As Integer
Dim key As String

'
Application.ScreenUpdating = False
clear
Application.Goto Reference:="keyname2"
 key = Range("keyname2").Value


    For x = 2 To 10000
Application.Goto Reference:="startme"
If Range("a" & x) = key Then


    Range("a" & x & ":P" & x).Select
    Selection.Copy


Application.Goto Reference:="query2"
    Selection.End(xlUp).Select
  y = ActiveCell.Row + 1
      Range("a" & y).Select



    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False

End If
Next x

Application.Goto Reference:="keyname2"
End Sub 

0 个答案:

没有答案