Ola,
Tenho a seguinte macro (abaixo).
Como vcs podem ver, eu repito muito os comandos
If ((wksSheet.Range("D" & row).Value = "X")) Then
'Insert the name in the active cell and then increment the row
ActiveCell.Value = wksSheet.Range("A" & row).Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = wksSheet.Range("D" & row).Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "casado"
ActiveCell.Offset(1, -2).Select
i = i + 1
Por isto, eu gostaria de criar uma funcao onde eu desse como argumentos o nome da coluna (A, B, C etc.), a linha (variavel row) e o valor q eu quero procurar (no caso X, mas eu quero algo q possa ser flexivel, tipo uma variavel).
Eh possivel criar esse tipo de funcao? Alguem pode me ajudar?
Desde ja agradeco,
Fernanda
Sub Selectionner()
Dim wksSheet As Worksheet
Dim i As Integer
Dim row As Integer
Dim Lin As Integer
For Each wksSheet In ThisWorkbook.Worksheets
'Use an another sheet to search
row = 2
Do
If (wksSheet.Name <> ActiveSheet.Name) Then
If ((wksSheet.Range("A" & row).Value = "paulo")) Then
If ((wksSheet.Range("D" & row).Value = "X")) Then
'Insert the name in the active cell and then increment the row
ActiveCell.Value = wksSheet.Range("A" & row).Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = wksSheet.Range("D" & row).Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "casado"
ActiveCell.Offset(1, -2).Select
i = i + 1
End If
If ((wksSheet.Range("E" & row).Value = "X")) Then
'Insert the name in the active cell and then increment the row
ActiveCell.Value = wksSheet.Range("A" & row).Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = wksSheet.Range("E" & row).Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "casado"
ActiveCell.Offset(1, -2).Select
i = i + 1
End If
End If
row = row + 1
Loop Until row = 8
Next wksSheet
'Fonction to count the number of rows
Lin = Sheets("1").Range("A65000").End(xlUp).row
MsgBox "There were " & i & " results", vbOKCancel, "Found results"
End Sub