Find column and position the cursor in it

5

I have a spreadsheet that contains:

COLUNA A1 CABECALHO (PRODUTOS)
COLUNAS B1 A BK1 COM DATAS

I will read a database ordered by product and date and I have     which automatically fill in the worksheet by allocating the values of each product on their respective dates.

PRODUTOS     01/10/2016   02/10/2016   03/10/2016 .......  30/10/2016
PRODUTO1                     R$ 1,00      R$ 2,00
PRODUTO2      R$ 5,00                                      R$ 10,00

How to locate column and position the cursor in it?  I forgot to tell you, but I'm using VBA inside Excel as a development tool.

    
asked by anonymous 21.10.2016 / 20:20

1 answer

6

One option would be:

Create a function to get the date the user wants and position on the date:

Sub buscaData()

Dim DATA_ As String
Dim CELULA_ As Range
Dim RESPOSTA_ As Long



    DATA_ = Application.InputBox(Prompt:="Qual a data desejada?", _
                Title:="BUSCAR DATA", Default:=Format(Date, "Short Date"), Type:=1)
    If DATA_ = "False" Then Exit Sub

    DATA_ = Format(DATA_, "Short Date")

    On Error Resume Next
        Set CELULA_ = Cells.Find(What:=CDate(DATA_), After:=Range("A1"), LookIn:=xlFormulas _
            , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    On Error GoTo 0

    If CELULA_ Is Nothing Then
        RESPOSTA_ = MsgBox("Data não encontrada, deseja buscar outra data?", vbInformation + vbYesNo)
        If RESPOSTA_ = vbYes Then Run "buscaData":
    Else
        CELULA_.Select
    End If

End Sub

Adapted function of link

I hope I have helped!

    
21.10.2016 / 21:15