将字符附加到单元格值以下程序可搜索选中的列,并将一个字符(在此示例中为撇号)附加到每个条目的开头。如果您已经选定了范围,并且没有声明 Option Explicit,则代码会如示例所示运行。如果只选择了一个单元格,那么代码仅在活动单元格中操作。 Sub AddApostrophe() Dim cell as Range for each cell in Selection if not cell.hasformula then if not isempty(cell) then cell.Value = "'" & cell.Value End if end if Next End sub 上述代码的变体只将字符(撇号)放在数字单元格中。该代码只在所选的数字单元格中操作。 Sub AddApostrophe() Dim cell as Range for each cell in Selection if not cell.hasformula then if not isempty(cell) then if isnumeric(cell) then 'Change the character as needed. cell.Value = "'" & cell.Value end if End if end if Next End sub 小结本文介绍了可在 Excel 中使用的许多技巧和 Microsoft Visual Basic for Applications (VBA) 代码。通过使用这些程序以及对它们进行修改以满足您自己的使用所需,可以使自己的应用程序更加健壮,并为您的用户提供更多的选择。 (责任编辑:admin) |