J'ai une macro VBA qui s'exécute et doit souvent avoir "=" comme premier caractère dans une cellule. Les cellules sont remplies de valeurs telles que «= domestique», «<> domestique», etc.
À l'heure actuelle, je replace "=" par "IS" en tant que quickfix, mais j'aimerais que je puisse garder le signe égal, pour la cohérence avec les cellules qui utilisent des symboles tels que "<>". Lorsque j'essaie, Excel pense que c'est une fonction avec une mauvaise syntaxe. J'utilise Cells(row, col).Value = x
, où x
est la string qui peut ou non commencer par "=", pour entrer datatables.
Ajouter une seule citation '
au début de la string:
Cells(row, col).Value = "'" & x
et vous obtiendrez ce que vous voulez.
C'est une méthode alternative
Sub Test() Dim myRange As Range Set myRange = Range("C:C") 'Column "C" myRange.NumberFormat = "@" 'Set cell format of range to plain text myRange.Cells(1, 1) = "= Domestic" End Sub
Sous test ()Sub Test() Dim myRange As Range Set myRange = Range("C:C") 'Column "C" myRange.NumberFormat = "@" 'Set cell format of range to plain text myRange.Cells(1, 1) = "= Domestic" End Sub
Dim myRange As RangeSub Test() Dim myRange As Range Set myRange = Range("C:C") 'Column "C" myRange.NumberFormat = "@" 'Set cell format of range to plain text myRange.Cells(1, 1) = "= Domestic" End Sub
Définir myRange = Plage ("C: C") 'Colonne "C"Sub Test() Dim myRange As Range Set myRange = Range("C:C") 'Column "C" myRange.NumberFormat = "@" 'Set cell format of range to plain text myRange.Cells(1, 1) = "= Domestic" End Sub
myRange.NumberFormat = "@" 'Définir le format de la cellule de la plage vers le text brutSub Test() Dim myRange As Range Set myRange = Range("C:C") 'Column "C" myRange.NumberFormat = "@" 'Set cell format of range to plain text myRange.Cells(1, 1) = "= Domestic" End Sub
myRange.Cells (1, 1) = "= Domestic"Sub Test() Dim myRange As Range Set myRange = Range("C:C") 'Column "C" myRange.NumberFormat = "@" 'Set cell format of range to plain text myRange.Cells(1, 1) = "= Domestic" End Sub
Par rapport à la réponse de manji, il ne fournit aucune amélioration de la performance ou de la taille … tout simplement différent.