Read string from one column and return values in another in vba

Asked

Viewed 145 times

-1

Hello,

I don’t know much about VBA and wanted to know if someone could help me.

I would like to know how I can take a string from a column(e.g., A), read its data and return it in a new column. In this new column it would be returned "true" if it were "A", "false" if it were different from "A".

And that code would read all the lines in that column with the string.

Does anyone have any idea how I do it ?

I’ve searched and I can’t find anything like that.

The code I made to test this idea was this (it brings as if all the lines were different from A):

Private Sub cmdaon_Click()


Dim counter As Integer
Dim rng1 As Range

Set rng1 = destSheet1.Range("A:L")

Ln = 2

Do While rng1.Cells(Ln, 1).Value <> ""

   If Cells(Ln, 9).Value = "A" Then

         Cells(Ln, 13).Select
         Cells(Ln, 13).Value = "Verdadeiro"
   Else

      Cells(Ln, 13).Value = "Falso"

    End If


    Ln = Ln + 1
Loop

End Sub

1 answer

0

Sub Macro1()
'Dados na coluna A e resultado na coluna E (offset 0,4)
' Macro1 Macro
'

'
Dim rng1 As Range
Set rng1 = Range("A1:A8")
Dim dados As Range


For Each dados In rng1
    If dados.Value = "A" Then
        dados.Offset(0, 4).Value = "Verdadeiros"
    Else: dados.Offset(0, 4).Value = "Falso"
    End If
Next
End Sub

Browser other questions tagged

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