Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

comparer une colonne d'un workbook source avec 2 autres workbook

3 réponses
Avatar
ktran
Bonjour,

j ai ecris un code mais ca bug.

la situation est : j ai un workbook source nomme "testforward", colonne G et a partir de G4, j ai des noms.

la macro doit verifier pour chaque cellule de G4 jusqu a la premiere cellule vide du workbook "testforward" ou se trouve ce nom ; soit dans le workbook "danhmuc8020" ou dans le workbook "danhmuc", et ensuite dans un msgbox specifier dans quel workbook se trouve le nom.

voici le code ecrit :

Sub compare()
myway = ActiveWorkbook.Path & "\"
Dim cp As Integer
Dim K As Integer
Dim Danhmuc8020 As Workbook
Set Danhmuc8020 = GetObject(myway & "\Danhmuc8020.xls")
Dim DANHMUCCAMCO As Workbook
Set DANHMUCCAMCO = GetObject(myway & "\DANHMUCCAMCO.xls")
For K = 4 To Sheets("FW").[G65000].End(4).Row
cp = 0
cp = Application.Match(Cells(K, 7), Danhmuc8020.Sheets("Hanmucgiaingan").[B3:B16], 0)
If cp = 0 Then
MsgBox "ok"
Else
cp = Application.Match(Cells(K, 7), DDANHMUCCAMCO.Sheets("HOSE" & "HASTC").[B4:B], 0)
If cp = Cells(4, K) Then
MsgBox "DANHMUCCAMCO"
K = K + 1
End If
Next
End Sub

3 réponses

Avatar
Jacky
Bonjour,

Code non testé..mais
Si ceci
For K = 4 To Sheets("FW").[G65000].End(4).Row


doit boucler de la colonne "G" de la ligne 4 à la dernière ligne occupée, il
faut remplacer End(4) par End(3)
ou compatible xl2007
For K = 4 To Sheets("Feuil1").Cells(Rows.Count, 7).End(3).Row

Bon courage
--
Salutations
JJ


"ktran" a écrit dans le message de news:

Bonjour,

j ai ecris un code mais ca bug.

la situation est : j ai un workbook source nomme "testforward", colonne G
et a
partir de G4, j ai des noms.

la macro doit verifier pour chaque cellule de G4 jusqu a la premiere
cellule
vide du workbook "testforward" ou se trouve ce nom ; soit dans le workbook
"danhmuc8020" ou dans le workbook "danhmuc", et ensuite dans un msgbox
specifier
dans quel workbook se trouve le nom.

voici le code ecrit :

Sub compare()
myway = ActiveWorkbook.Path & ""
Dim cp As Integer
Dim K As Integer
Dim Danhmuc8020 As Workbook
Set Danhmuc8020 = GetObject(myway & "Danhmuc8020.xls")
Dim DANHMUCCAMCO As Workbook
Set DANHMUCCAMCO = GetObject(myway & "DANHMUCCAMCO.xls")
For K = 4 To Sheets("FW").[G65000].End(4).Row
cp = 0
cp = Application.Match(Cells(K, 7),
Danhmuc8020.Sheets("Hanmucgiaingan").[B3:B16], 0)
If cp = 0 Then
MsgBox "ok"
Else
cp = Application.Match(Cells(K, 7), DDANHMUCCAMCO.Sheets("HOSE" &
"HASTC").[B4:B], 0)
If cp = Cells(4, K) Then
MsgBox "DANHMUCCAMCO"
K = K + 1
End If
Next
End Sub


Avatar
Jacky
Re..
For K = 4 To Sheets("FW").Cells(Rows.Count, 7).End(3).Row
Evidemment et non pas
For K = 4 To Sheets("Feuil1").Cells(Rows.Count, 7).End(3).Row


--
Salutations
JJ


"Jacky" a écrit dans le message de news:
%
Bonjour,

Code non testé..mais
Si ceci
For K = 4 To Sheets("FW").[G65000].End(4).Row


doit boucler de la colonne "G" de la ligne 4 à la dernière ligne occupée,
il
faut remplacer End(4) par End(3)
ou compatible xl2007
For K = 4 To Sheets("Feuil1").Cells(Rows.Count, 7).End(3).Row

Bon courage
--
Salutations
JJ


"ktran" a écrit dans le message de news:

Bonjour,

j ai ecris un code mais ca bug.

la situation est : j ai un workbook source nomme "testforward", colonne G
et a
partir de G4, j ai des noms.

la macro doit verifier pour chaque cellule de G4 jusqu a la premiere
cellule
vide du workbook "testforward" ou se trouve ce nom ; soit dans le
workbook
"danhmuc8020" ou dans le workbook "danhmuc", et ensuite dans un msgbox
specifier
dans quel workbook se trouve le nom.

voici le code ecrit :

Sub compare()
myway = ActiveWorkbook.Path & ""
Dim cp As Integer
Dim K As Integer
Dim Danhmuc8020 As Workbook
Set Danhmuc8020 = GetObject(myway & "Danhmuc8020.xls")
Dim DANHMUCCAMCO As Workbook
Set DANHMUCCAMCO = GetObject(myway & "DANHMUCCAMCO.xls")
For K = 4 To Sheets("FW").[G65000].End(4).Row
cp = 0
cp = Application.Match(Cells(K, 7),
Danhmuc8020.Sheets("Hanmucgiaingan").[B3:B16], 0)
If cp = 0 Then
MsgBox "ok"
Else
cp = Application.Match(Cells(K, 7), DDANHMUCCAMCO.Sheets("HOSE" &
"HASTC").[B4:B], 0)
If cp = Cells(4, K) Then
MsgBox "DANHMUCCAMCO"
K = K + 1
End If
Next
End Sub







Avatar
ktran
ktran a écrit le 09/01/2010 à 13h12 :
Bonjour,

j ai ecris un code mais ca bug.

la situation est : j ai un workbook source nomme "testforward",
colonne G et a partir de G4, j ai des noms.

la macro doit verifier pour chaque cellule de G4 jusqu a la premiere cellule
vide du workbook "testforward" ou se trouve ce nom ; soit dans le
workbook "danhmuc8020" ou dans le workbook "danhmuc", et
ensuite dans un msgbox specifier dans quel workbook se trouve le nom.

voici le code ecrit :

Sub compare()
myway = ActiveWorkbook.Path & ""
Dim cp As Integer
Dim K As Integer
Dim Danhmuc8020 As Workbook
Set Danhmuc8020 = GetObject(myway & "Danhmuc8020.xls")
Dim DANHMUCCAMCO As Workbook
Set DANHMUCCAMCO = GetObject(myway & "DANHMUCCAMCO.xls")
For K = 4 To Sheets("FW").[G65000].End(4).Row
cp = 0
cp = Application.Match(Cells(K, 7),
Danhmuc8020.Sheets("Hanmucgiaingan").[B3:B16], 0)
If cp = 0 Then
MsgBox "ok"
Else
cp = Application.Match(Cells(K, 7), DDANHMUCCAMCO.Sheets("HOSE" &
"HASTC").[B4:B], 0)
If cp = Cells(4, K) Then
MsgBox "DANHMUCCAMCO"
K = K + 1
End If
Next
End Sub


j ai bien re-ecris comme tu me la conseille mais j ai toujours un erreur "mismatch" comme la macro arrive sur ligne : cp = application.match....

Private Sub compare()
myway = ActiveWorkbook.Path & ""
Dim cp As Integer
Dim K As Integer
Dim Danhmuc8020 As Workbook
Set Danhmuc8020 = GetObject(myway & "Danhmuc8020.xls")
Dim DANHMUCCAMCO As Workbook
Set DANHMUCCAMCO = GetObject(myway & "DANHMUCCAMCO.xls")
For K = 4 To Sheets("FW").Cells(Rows.Count, 7).End(3).Row
cp = 0
cp = Application.Match(Cells(K, 7), Danhmuc8020.Sheets("Hanmucgiaingan").[B3:B16], 0)
If cp = 0 Then
MsgBox "ok"
Else
cp = Application.Match(Cells(K, 7), DDANHMUCCAMCO.Sheets("HOSE").[B4:B], 0)
If cp = Cells(4, K) Then
MsgBox "DANHMUCCAMCO"
K = K + 1
End If
End If
Next K
End Sub