Home > front end >  VBA Excel Macro find column name and next need to copy range
VBA Excel Macro find column name and next need to copy range

Time:09-24

I have a part of macro which, after typing in the inputbox, finds the name of the column (date), after finding it, it needs to copy a given fragment of rows from this column, always after finding a given cell, it will be the same range. But i dont knot excatly how please take a look as below code

''' Put date input box  '''
    Do
        inputbx = InputBox("Provide date, FORMAT; YYYY-MM-DD")
        If inputbx = vbNullString Then Exit Sub
        On Error Resume Next
        vDate = CDate(inputbx)
        On Error GoTo 0
        DateIsValid = IsDate(vDate)
        If Not DateIsValid Then MsgBox "Please enter a valid date.", vbExclamation
    Loop Until DateIsValid
''' loop'''
     With data_wb.Sheets("Final")
        Set Loc = .Cells.Find(what:=Format(inputbx, "YYYY-MM-DD"))
        If Not Loc Is Nothing Then
            Loc.Range("109:123").Copy

CodePudding user response:

With data_wb.Sheets("Final")
    Set loc = .Cells.Find(what:="2021-01-01")
    If Not loc Is Nothing Then
        .Cells(109, loc.Column).Resize(15).Copy


    End If
End With

alternative

    If Not loc Is Nothing Then
        loc.EntireColumn.Rows("109:123").Copy
    End If

  • Related