2013-01-02 72 views
0

我需要一個將在excel中用作宏的vb腳本。VB腳本空間

我需要數據有空格的行才能刪除空格。我知道如何一次創建一個公式單元,但我無法知道如何用循環腳本大規模地完成此任務。任何幫助,將不勝感激。

+0

您可以使用'Trim'在該列上執行相同操作。該函數將刪除該字符串的'pre'和'post'位置的空格! – CodeLover

+0

我正在尋找刪除字符串中的空格。所以'PR 026R'將'PR026R'。並讓它查看列中的每一行並「修復」它。 – user1942137

+0

你想要什麼? VBA或VBScript?請更正您的標籤。 – Fionnuala

回答

0

試試這個代碼:

Columns("F:F").Select 

Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _ 
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ 
    ReplaceFormat:=False 

我試試「用無(‘)來代替空格字符(’)」

1

不很瞭解的萬分之一,但在VB腳本您可以使用以下代碼: -

Option Explicit 
Dim objFso,strFileName,objFile 
Set objFso = CreateObject("Scripting.FileSystemObject")   
strFileName="C:\Documents and Settings\amolc\Desktop\test.txt" ''Path of text file 

Set objFile = objFso.OpenTextFile(strFileName,1) 
strText = objFile.ReadAll 
objFile.Close 
strText = Replace(strText," ","",vbTextCompare)   ''Replace function to remove space 
Set objFile = objFso.OpenTextFile(strFileName,2) 
objFile.Write (strText) 
objFile.Close 
+1

美好的決議!太棒了! –