Search for items that are in within a given month of the year

Asked

Viewed 40 times

0

I need to mount a macro for a spreadsheet that I am working on. I have a table with several columns in the tab ordem (in the date column has several dates with month and year type "22/02/2018), and needed a macro to, when typing a month and year ("02/2018") in a cell in the billing tab, be made the copy of the lines whose date cell is within this month.

I don’t need to copy the entire row, only certain columns that I will determine as needed.

inserir a descrição da imagem aqui

1 answer

0

Your code will be something similar to the one below. Change the object columns sheets(A).cells(linha,coluna) by the columns you want.

Note: I put two dates: one for the first day of the month and another for the last, to mark the interval. Then you will have to type two dates instead of one month.

sub exemplo()
dim data_inicio as date, data_fim as date
dim linha as double
data_inicio = sheets("faturamento").cells(1,3).value
data_fim = sheets("faturamento").cells(1,4).value
linha_ordem= 'número da 1ª linha da tabela de ordens

do
    if sheets("ordem").cells(linha_ordem,"coluna das datas").value>=data_inicio and sheets("ordem").cells(linha_ordem,"coluna das datas")<=data_fim then
        sheets("faturamento").cells(linha_faturamento,"coluna destino").value = sheets("ordem").cells(linha_ordem, "coluna a ser copiada").value
        linha_faturamento = linha_faturamento + 1
    end if
    linha_ordem = linha_ordem + 1
loop until sheets("ordem").cells(linha_ordem,"coluna das datas").value=""
end sub

Browser other questions tagged

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