Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

modification de mon code

  • Initiateur de la discussion Initiateur de la discussion bpol
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

bpol

XLDnaute Impliqué
re le forum,

dans une macro j'ai cette partie de code:

Trouver la colonne
choixCol = 0
For col = 6 To 9
If Cells(choixLig, col) = 0 Then
choixCol = col
Exit For
End If
Next col

If choixCol = 0 Then
MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
Exit Sub
End If

' Afficher le résultat
Cells(choixLig, choixCol).Value = Range("I1").Value

Or je voudrais que l'enregistrement se fasse dans
la colonne 6 (F) si F3>1
colonne 7 (G) si G3>1
colonne 8 (H) si H3>1
colonne 6 (I) si I3>1

car pour l'instant cela cherche la 1ere colonne vide

est ce que quelqu'un pourrait m'aider parce que là c'est au dessus de mes compétences?

Merci
BPOL
 
Dernière édition:
Re : modification de mon code

Bonjour


Code à tester
if choixLig = 3 and Cells(choixLig, col) >1

JP
 
Re : modification de mon code

Re JP,

voici le code complet:

'Private Sub cmdEnregistrer_Click()
Dim lig As Long
Dim choixLig As Long
Dim col As Long
Dim choixCol As Long

' Trouver la ligne
choixLig = 0

For lig = 7 To 256
If Range("E7") = 0 Then choixLig = 7: Exit For

If Range("E" & lig) = Range("E1") Then choixLig = lig: Exit For

If Range("E" & lig) = 0 And Range("F3") > 1 Then
lig = Range("E65536").End(xlUp).Row + 1
Cells(lig, 5) = Range("E1")
choixLig = lig: Exit For
End If
Next lig

Cells(choixLig, 5) = Range("E1")

' If choixLig = 0 Then
' MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
' Exit Sub
' End If

' Trouver la colonne
choixCol = 0
For col = 6 To 9
If Cells(choixLig, col) = 0 Then
choixCol = col
Exit For
End If
Next col

If choixCol = 0 Then
MsgBox "L'enregistrement n'est pas possible", vbCritical + vbOKOnly, "Erreur"
Exit Sub
End If

' Afficher le résultat
Cells(choixLig, choixCol).Value = Range("I1").Value

ETC...


BPOL
 
Re : modification de mon code

Bonsoir

A priori on ne passe jamais dans la ligne 3
le code ci dessous
For lig = 7 To 256
If Range("E7") = 0 Then choixLig = 7: Exit For

If Range("E" & lig) = Range("E1") Then choixLig = lig: Exit For

If Range("E" & lig) = 0 And Range("F3") > 1 Then
lig = Range("E65536").End(xlUp).Row + 1
Cells(lig, 5) = Range("E1")
choixLig = lig: Exit For
End If
Next lig

donnera soit
choixLig = 7
soit
choixLig = lig ( 7 à 256)

En mettant un espion sur choixLig on peut voir la valeur
JP
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
4
Affichages
281
Réponses
5
Affichages
915
Réponses
4
Affichages
735
Réponses
10
Affichages
667
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…