1
I have a spreadsheet with the following information.
I want to create a new sheet with some columns of this sheet and transform the columns Nominal, Humidity, Primeira_delivery, Degree Drink, Standard, Medicinal and Restr_horario in a column called ITEM and the value of these columns in another column called FLAG.
My new spreadsheet would look like this:
I also want to create the N_ITEM column which is based on the value of the ITEM column.
If Item = STANDARD then N_ITEM = 1,
If Item = NOMINAL, MOISTURE, GRAU_BEBIDA, MEDICINAL then N_ITEM = 2
If Item = PRIMEIRA_ENTREGA then N_ITEM = 4
If Item = RESTR_HORARIO then N_ITEM = 5.
I did the macro below, but it’s not working...
Public Sub Atualizar()
'
'faz outra tabela listando cada ganho individual
'facilita a manipulação de pivot's
Dim BD As Worksheet
Dim base As Worksheet
Dim b As Integer
Dim c As Integer
Dim itens As Range
Dim k As Long
Set BD = Sheets("Base_Distribuicao")
Set base = Sheets("base")
Application.ScreenUpdating = False
With base
.Range("A:M").ClearContents
.Range("a1").Value = "Cod_JDE"
.Range("B1").Value = "CNPJ_8"
.Range("C1").Value = "CNPJ"
.Range("D1").Value = "CLIENTE"
.Range("E1").Value = "REGIAO"
.Range("F1").Value = "SUBREGIAO"
.Range("G1").Value = "NEGOCIO"
.Range("H1").Value = "PUBLICO_PRIVADO"
.Range("I1").Value = "CDL_RESPONSAVEL"
.Range("J1").Value = "PRODUTO"
.Range("K1").Value = "ITEM"
.Range("L1").Value = "N_ITEM"
.Range("M1").Value = "FLAG"
End With
BD.Select
k = BD.Range("A1", BD.Range("A1").End(xlDown)).Rows.Count
For c = 1 To 7 'contagem de colunas dos itens, ajuda a generalizar o preenchimento por offset
If itens Is Nothing Then 'definindo a ptimeira coluna
Set itens = BD.Range("A1:AB5000").Find(what:="Nominal")
itens.Offset(1, 0).Select
Else
Set itens = itens.Offset(0, 1) 'definindo as colunas restantes
itens.Offset(1, 0).Select 'primeiro flag do item
End If
For b = 1 To k
If ActiveCell.Value <> "" And ActiveCell.Value <> "-" Then
base.Range("A2").EntireRow.Insert
Else
base.Range("A2") = ActiveCell.Offset(0, -(5 + c)).Value
base.Range("B2") = ActiveCell.Offset(0, 14 - c).Value
base.Range("C2") = ActiveCell.Offset(0, 15 - c).Value
base.Range("D2") = ActiveCell.Offset(0, 16 - c).Value
base.Range("E2") = ActiveCell.Offset(0, 17 - c).Value
base.Range("F2") = ActiveCell.Offset(0, 18 - c).Value
base.Range("G2") = ActiveCell.Offset(0, 19 - c).Value
base.Range("H2") = ActiveCell.Offset(0, 20 - c).Value
base.Range("I2") = ActiveCell.Offset(0, -(3 + c)).Value
base.Range("J2") = ActiveCell.Offset(0, -(2 + c)).Value
base.Range("M2") = ActiveCell.Value
base.Range("K2") = itens.Value
End If
ActiveCell.Offset(1, 0).Select ' proximo flag
Next
Next
Application.ScreenUpdating = True
End Sub
Hello Thaís, welcome! Please, if you can, make the statement clearer and sometimes more simplified because it would be easier to answer. Instead of putting the real, contextual problem of your company, you could narrow it down and ask the question directly to the point: I have a spreadsheet A with columns (name, street, neighborhood, city, number, zip code) - I would like to create a column B, with the columns name and address - is the same problem but in a way that people understand better.
– Mateus