excel - 使用 Trim 功能删除不需要的多余字符

标签 excel vba

我正在尝试将 C 列中包含数据的所有单元格修剪到最左边的 9 个字符。

Sub TrimColumns()
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row

     If LastRow > Columns("B").Row Then
        Range("C2:C" & LastRow).LTrim(1,9) ' getting syntax error on this line 
     End If 
End Sub
Range("C2:C" & LastRow).LTrim(1,9) ' 在这一行出现语法错误

最佳答案

只需使用 Left ?

Cells(1,1).value = Left(Cells(1,1).value,9)

这将在范围内循环:
For i = 1 to LastRow Step 1
    Cells(i,3).value = Left(Cells(i,3).value,9)
Next i

关于excel - 使用 Trim 功能删除不需要的多余字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56636301/

相关文章:

vba - 通过宏导入 CSV 时日期格式不一致

excel - 运行调用和 Excel 脚本的 vba 脚本时,电子邮件停止发送

excel - VLookUp 函数 VBA - 未返回所需值

vba - 使用 VBA 打开和关闭条件格式

excel - 用于搜索字符串,然后搜索第二个字符串并从文本文件返回数据行的 VBA 代码

字符串数组上的 VBA "Type mismatch: array or user-defined type expected”

excel - 使用范围,如何将 .COPY DESTINATION 粘贴为值

VBA防止代码中的 "End"关闭用户窗体

performance - 如何在 Excel VBA 中更好地管理内存以防止宏变慢?

excel - 使用 VBA 将 Sum 与 CountIfs 一起使用