Code with Repetition vba

Asked

Viewed 25 times

-1

The code below does not execute on the following lines:

Sub concatena()
 
linha = 13

Do While Cells(linha, 2) <> ""


Dim Data As String
    Data = Cells(linha + 1, 2)

  Range("q13").Select
    ActiveCell.Value = Format(Data, "mmmm" & "yyyy")
  Range("r13").Select
    ActiveCell.Value = Range("q13") & Range("k13")
  Range("v13").Select
    Selection = Range("i13") & Range("n13") & Range("j13")

With Selection

Dim x As String
    x = Cells(linha, 2)

If x < Sheets("FLC").Range("m4") Then
  Range("s13") = Sheets("FLC").Range("E9")
Else
  Range("s13") = Sheets("FLC").Range("F9")
End If

If x < Sheets("FLC").Range("m4") Then
  Range("t13") = Range("i13") & Sheets("FLC").Range("E9")
Else
  Range("s13") = Range("i13") & Sheets("FLC").Range("F9")
End If

If x < Sheets("FLC").Range("m4") Then
  Range("u13") = Sheets("Tabelas").Range("w2") & Range("j13") & Range("i13")
Else
  Range("u13") = Sheets("Tabelas").Range("w3") & Range("j13") & Range("i13")
End If

End With

  linha = linha + 1
Loop

End Sub
  • Gives what mistake, and where?

  • Also, I have the impression that the code could be better architected. If you could explain better what your intention is and what the context is, it would be easier to give an answer.

1 answer

0

Can you share the error with us? Maybe then we can be more assertive in a solution. However, I saw that your code lacks an instruction. Can you test this way? Just add ". value" already solves.

Sub concatena()
 
linha = 13

Do While Cells(linha, 2).value <> ""


Dim Data As String
    Data = Cells(linha + 1, 2).value

  Range("q13").Select
    ActiveCell.Value = Format(Data, "mmmm" & "yyyy")
  Range("r13").Select
    ActiveCell.Value = Range("q13") & Range("k13")
  Range("v13").Select
    Selection = Range("i13").value & Range("n13").value & Range("j13").value

With Selection

Dim x As String
    x = Cells(linha, 2)

If x < Sheets("FLC").Range("m4").value Then
  Range("s13").value = Sheets("FLC").Range("E9").value
Else
  Range("s13").value = Sheets("FLC").Range("F9").value
End If

If x < Sheets("FLC").Range("m4").value Then
  Range("t13").value = Range("i13").value & Sheets("FLC").Range("E9").value
Else
  Range("s13").value = Range("i13").value & Sheets("FLC").Range("F9").value
End If

If x < Sheets("FLC").Range("m4").value Then
  Range("u13").value = Sheets("Tabelas").Range("w2").value & Range("j13") & Range("i13").value
Else
  Range("u13").value = Sheets("Tabelas").Range("w3").value & Range("j13") & Range("i13").value
End If

End With

  linha = linha + 1
Loop

End Sub

Browser other questions tagged

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