VBA- Code application de style à un tableau

Bonjour,

Je dois appliquer un style prédéfini à un tableau dont la plage est variable.

Le tableau est de la forme C9:H9 et peut s'étendre sur un nombre infini de ligne.

J'ai utilisé la macro recorder pour créer le code, puis l'ai modifié pour qu'il s'adapte à mon fichier mais sans succés. Pourriez vous m'aider ?

Worksheets(1).Activate

Cells(9 + 1, 3).Select

Range(Selection, Selection.End(xlToRight)).Select

Range(Selection, Selection.End(xlDown)).Select

ActiveSheet.Selection.TableStyle = "TableStyleLight1"

Merci

Bonjour et bienvenu(e)

TableStyle ne s'applique qu'aux ListObjects (Tableau), alors avant de l'utiliser il faut le créer

Sub test()
  Worksheets(1).Activate
  Cells(9 + 1, 3).Select
  Range(Selection, Selection.End(xlToRight)).Select
  Range(Selection, Selection.End(xlDown)).Select
  With ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
    .Name = "Tableau1"
    .TableStyle = "TableStyleLight1"
  End With
End With

Bonjour et bienvenue sur le forum

Essaie ce code :

    Dim col As Single
    Dim ln As Single
    col = Cells(10, 3).End(xlToRight).Column
    ln = Cells(10, 3).End(xlDown).Row
    Range(Cells(10, 3), Cells(ln, col)).TableStyle = "TableStyleLight1"

Bonjour,

Demande pas claire et pas testé.

Public Sub test()
Dim ws As Worksheet
Dim objList As ListObject
Set ws = Worksheets(1)
With ws
Set objList = .ListObjects.Add(xlSrcRange, .Cells(9, 3).CurrentRegion, xlYes)
With objList
.Name = "Tableau1"
.Comment = ""
.TableStyle = "TableStyleLight1"
End With
End With
Set ws = Nothing
End Sub

Ca fonctionne à la perfection !

Merci !

Rechercher des sujets similaires à "vba code application style tableau"