XL 2019 inserer une valeur textbox dans la dernière cellule vide horizontalement

escudo

XLDnaute Nouveau
bonjour tout le monde,
voici ma situation, j'aimerais envoyer la valeur d'un textbox vers la cellule vide de la dernière colonne vide de la ligne déjà spécifié d'une manière horizontale ;
j'ai mis ce code mais ca n'a pas marcher
Sub ENVOYER()
Dim cel As Range
Dim col As Integer
Dim i As Long
Application.Calculation = xlCalculationManual

VAR1 = ComboBox1.Value
With Sheets("VAR_PRIX")
Set cel = .Columns("a").Find(what:=VAR1, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows)
End With
Me.ENREG = cel.Row
NOEnreg = ENREG
col = Sheets("VAR_PRIX").Cells(1, Sheets("VAR_PRIX").Columns.Count).End(xlToLeft).Column
For i = 1 To col
If TextBox1 <> "" And TextBox1 <> TextBox29 Then
Sheets("VAR_PRIX").Cells(NOEnreg, i) = CDbl(TextBox1.Value)
Sheets("VAR_PRIX").Calculate


Exit For
End If
Next i
End Sub

voici un fichier exemple
 

Pièces jointes

  • EXEMPLE.xlsm
    430.9 KB · Affichages: 5
Solution
Bonsoir escudo,

Cela ne pose aucun problème, voyez ce fichier (2) et la macro modifiée :
VB:
Private Sub CommandButton1_Click()
Dim c As Range, v#
Combobox1_Change
If lig = 0 Then Exit Sub
If TextBox1 = "" Then TextBox1.SetFocus: Exit Sub
Set c = P.Rows(lig).Find("", P.Cells(lig, 2), xlValues)
v = Val(Replace(TextBox1, ",", "."))
If v > 0 Then c = Date: c(1, 2) = v
c(1, 2).Interior.ColorIndex = 6 'jaune
Application.Goto c(1, 2)
End Sub
C'est la date du jour qui est entrée.

A+

job75

XLDnaute Barbatruc
Bonjour escudo, Eric, le forum,

J'ai revu l'ensemble du code de l'UserForm :
VB:
Dim P As Range, lig& 'mémorose les variables

Private Sub Combobox1_Change()
TextBox2 = ""
lig = ComboBox1.ListIndex + 1
If ComboBox1 = "" Then Exit Sub
If lig = 0 Then ComboBox1 = "": Exit Sub
TextBox2 = P.Cells(lig, 2)
End Sub

Private Sub CommandButton1_Click()
Dim c As Range, v#
Combobox1_Change
If lig = 0 Then Exit Sub
If TextBox1 = "" Then TextBox1.SetFocus: Exit Sub
Set c = P.Rows(lig).Find("", P.Cells(lig, 2), xlValues)
v = Val(Replace(TextBox1, ",", "."))
If v > 0 Then c = v
Application.Goto c
End Sub

Private Sub UserForm_Initialize()
Dim h&
With Sheets("VAR_PRIX")
    With .Rows("5:" & .Cells.SpecialCells(xlCellTypeLastCell).Row)
        If .Row < 5 Then Exit Sub
        .Sort .Columns(1), xlAscending, Header:=xlNo 'tri alphabétique
        h = Application.CountA(.Columns(1))
        If h Then Set P = .Resize(h) Else Exit Sub
    End With
    ComboBox1.List = P.Columns(1).Resize(, 2).Value 'au moins 2 éléments
End With
End Sub
Edit : ajouté le test avec la variable h.

Il n'est pas nécessaire de convertir le tableau en tableau structuré.

A+
 

Pièces jointes

  • EXEMPLE.xlsm
    431.1 KB · Affichages: 0
Dernière édition:

escudo

XLDnaute Nouveau
J'aimerais mettre une date pour chaque changement du tarif comme l'image montre: sodapdf-converted (1).jpg
 

job75

XLDnaute Barbatruc
Bonsoir escudo,

Cela ne pose aucun problème, voyez ce fichier (2) et la macro modifiée :
VB:
Private Sub CommandButton1_Click()
Dim c As Range, v#
Combobox1_Change
If lig = 0 Then Exit Sub
If TextBox1 = "" Then TextBox1.SetFocus: Exit Sub
Set c = P.Rows(lig).Find("", P.Cells(lig, 2), xlValues)
v = Val(Replace(TextBox1, ",", "."))
If v > 0 Then c = Date: c(1, 2) = v
c(1, 2).Interior.ColorIndex = 6 'jaune
Application.Goto c(1, 2)
End Sub
C'est la date du jour qui est entrée.

A+
 

Pièces jointes

  • EXEMPLE(2).xlsm
    78.7 KB · Affichages: 3
Dernière édition:

escudo

XLDnaute Nouveau
Bonsoir escudo,

Cela ne pose aucun problème, voyez ce fichier (2) et la macro modifiée :
VB:
Private Sub CommandButton1_Click()
Dim c As Range, v#
Combobox1_Change
If lig = 0 Then Exit Sub
If TextBox1 = "" Then TextBox1.SetFocus: Exit Sub
Set c = P.Rows(lig).Find("", P.Cells(lig, 2), xlValues)
v = Val(Replace(TextBox1, ",", "."))
If v > 0 Then c = Date: c(1, 2) = v
c(1, 2).Interior.ColorIndex = 6 'jaune
Application.Goto c(1, 2)
End Sub
C'est la date du jour qui est entrée.

A+
ca marche nickel; merci de m'avoir aider.
 

Discussions similaires

Réponses
2
Affichages
149

Statistiques des forums

Discussions
312 206
Messages
2 086 223
Membres
103 159
dernier inscrit
FBallea