Boucle recherche valeur VBA
Bonjour à toute la communauté,
Je me tourne vers vous car je galère depuis un petit moment sans trouver la solution.
Je cherche à colorer une cellule si la valeur recherchée est présente dans un autre onglet.
Ex:
Si valeur est présente dans onglet "temp" alors on colore la même valeur dans l'onglet 1.
Merci pour votre aide.
Gramy
Bonjour,
Bonjour Raja,
Tu as découvert les Smileys
Cdlt.
Toutes mes confuses
Ci-joint un fichier pour exemple.
Pour récapituler mon besoin :
Je souhaite colorer dans l'onglet TCD tous les "user_dst" qui apparaissent dans l'onglet "Temp"
Merci à vous pour votre aide et votre temps
Re,
Essaye une formule de MFC suivante :
=NB.SI(Temp!$A$2:$A$5;A5)Raja a écrit :Re,
Essaye une formule de MFC suivante :
=NB.SI(Temp!$A$2:$A$5;A5)
Merci pour ta réponse Raja,
Malheureusement j'ai déjà une macro qui génère ce fichier tous les jours à partir des données d'un .CSV
Je cherche à ajouter au code déjà existant du code qui me permettra de faire ce que je cherche à faire.
Attribute VB_Name = "Test"
Public CodeErreur As String
Const InputFile As String = "test.csv"
Public Const OutputFile As String = "test"
Sub Launch_test()
Call AddReference
Call Generate_test_Report
End Sub
Sub DisplayIt(Optional sDate As String = Empty)
Progressindicator.Show
End Sub
Sub Generate_test_Report(Optional sDate As String = Empty, Optional CSVFilePath As Variant = Empty)
On Error GoTo errorHandler
Application.DisplayAlerts = False
progress 5
Application.ScreenUpdating = False
Call AddReference
Dim sDashedDate As String
If sDate <> "" Then
progress 10
sDashedDate = Format(sDate, "yyyy-mm-dd")
If OutputExists(sDashedDate) Then GoTo customExit
Set oFSO = New Scripting.FileSystemObject
progress 15
CSVFilePath = "\\XXXX\YYYYY\BBBB\" & sDashedDate & "\" & InputFile
If Not oFSO.FileExists(CSVFilePath) Then CSVFilePath = Application.GetOpenFilename("CSV Files (*.csv), *.csv", , , , False)
End If
' Import CSV
progress 20
If CSVFilePath = "" Then CSVFilePath = Application.GetOpenFilename("CSV Files (*.csv), *.csv", , , , False)
If CSVFilePath = False Then
GoTo customExit
Else
Call ImportCSV(CSVFilePath)
End If
progress 25
' Récupération date des logs
If sDate = "" Then
Do
sDate = InputBox("Please enter logs date (JJ/MM/AAAA)", , Format(Now - 1, "dd/mm/yyyy"))
Loop Until Mid(sDate, 3, 1) = "/" And Mid(sDate, 6, 1) = "/"
End If
progress 30
sDashedDate = Format(sDate, "yyyy-mm-dd")
If OutputExists(sDashedDate) Then GoTo customExit
If Cells(1, 1) = "" And Cells(1, 2) = "" And Cells(2, 1) = "" And Cells(2, 2) = "" Then GoTo noDataExit
progress 35
Columns("D:D").Select
Selection.Replace What:=".", Replacement:=".", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").Select
ActiveSheet.ListObjects.Add(xlSrcRange, , , xlYes).Name = "RawData"
progress 40
Range("RawData[#All]").Select
ActiveSheet.ListObjects("RawData").TableStyle = "TableStyleMedium9"
Cells.Select
Cells.EntireColumn.AutoFit
Call DeleteUselessSheets
progress 45
Range("RawData[[#Headers],[event_time]]").Select
iCol = 1
While Cells(1, iCol) <> ""
If Columns(iCol).ColumnWidth > 80 Then Columns(iCol).ColumnWidth = 80
iCol = iCol + 1
progress 50
Wend
ActiveSheet.Name = "Raw Data"
' Création TCD
Sheets.Add Before:=Worksheets(1)
progress 55
Sheets(1).Name = "test_" & sDashedDate
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"RawData", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="'test_" & sDashedDate & "'!R3C1", TableName:="TCDtest", _
DefaultVersion:=xlPivotTableVersion14
Sheets(1).Select
Cells(3, 1).Select
progress 60
With ActiveSheet.PivotTables("TCDtest").PivotFields("user_dst")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("TCDtest").PivotFields("event_time")
.Orientation = xlRowField
.Position = 2
progress 65
End With
With ActiveSheet.PivotTables("TCDtest").PivotFields("referer")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("TCDtest").PivotFields("url")
.Orientation = xlRowField
.Position = 4
End With
progress 70
ActiveSheet.PivotTables("TCDtest").AddDataField ActiveSheet. _
PivotTables("TCDtest").PivotFields("disposition"), _
"Nombre de url", xlCount
ActiveSheet.PivotTables("TCDtest").PivotFields("user_dst").ShowDetail = False
Range("B:B").Select
ActiveSheet.PivotTables("TCDtest").PivotFields("user_dst").AutoSort _
xlDescending, "Nombre de url", ActiveSheet.PivotTables("TCDtest"). _
PivotColumnAxis.PivotLines(1), 1
progress 90
Range("A1").Select
If Columns("A:A").ColumnWidth > 80 Then
Columns("A:A").ColumnWidth = 80
End If
Range("A3").Select
'test
Sheets("Raw Data").Select
ActiveSheet.ListObjects("RawData").Range.AutoFilter Field:=4, Criteria1:= _
"=XXXXX", Operator:=xlOr, Criteria2:= _
"=YYYYYYYY"
Range("C:C").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Feuil2").Name = "temp"
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlYes
Sheets("Raw Data").Select
ActiveSheet.ListObjects("RawData").Range.AutoFilter Field:=4
'testsearch
'fin testsearch
'test fin
Set oFSO = New Scripting.FileSystemObject
If Not oFSO.FolderExists(sResultsPath & sDashedDate) Then oFSO.CreateFolder (sResultsPath & sDashedDate)
ActiveWorkbook.SaveAs Filename:= _
sResultsPath & sDashedDate & "\" & GetOutputFile(sDashedDate), FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
GoTo customExit
errorHandler:
CodeErreur = OutputFile & " - " & Err.Number & " - " & Err.Description
Debug.Print CodeErreur
Application.DisplayAlerts = False
ThisWorkbook.Close
GoTo customExit
noDataExit:
Call NoData(sDashedDate, OutputFile)
GoTo customExit
customExit:
progress 100
Progressindicator.Hide
End Sub