Find column and position cursor in it

Asked

Viewed 1,200 times

6

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 have which automatically fill in the spreadsheet by setting the values of each product on its 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 cursor in it? I forgot to inform, but I am using VBA inside Excel as development tool.

  • The bid, is that I will create the spreadsheet through a selection of start date and end date, so the user can select from any day/month/year. So far all right, the problem is how to position on the right dates.

1 answer

6


One option would be:

Create a function to pick up the date user wants and position on top of 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

Function adapted from http://www.ozgrid.com/VBA/find-dates.htm

I hope I’ve helped!

  • 1

    Ball show. 100%. I made a very loco code. I’ll set it to my need. I’m picking up the dates in a form using the dtpicker.

  • Dude. Gave problem. When executing code, cell always returns Nothing.

  • Is it because the cells are merging? BC, DE, FG, ...

  • I did something wrong. I checked and I did something stupid. Now it’s working.

  • Glad it worked out! Anything post here. Hug and success!

  • It was really worth your help. I liked it here.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.