我在excel表中有数据,标题在第1行,我想修剪它们,如下所示
例如
CT_CD_FILTER_AMT * _Integer
[TestClass]
public class EventSourceTests
{
[TestMethod]
public void MyEventSourceShouldBeValid()
{
var analyzer = new EventSourceAnalyzer();
analyzer.Inspect(MyEventSource.Log);
}
}
CT_CD_FILTER_AMT
每个列标题都不同......列数也与每个文件不同
所以我想选择每列的值并修剪它直到它到达空白单元格(仅限第1行)
请帮助代码。
TIA。
答案 0 :(得分:0)
Sub mac1()
Dim LastCol As Integer
Sheets("MySheet").Select
LastCol = Cells(1, 1).End(xlToRight).Column
For Each C In Range(Cells(1, 1), Cells(1, LastCol))
C.Value = Left(C.Value, InStr(C.Value, "") - 1)
Next C
End Sub
或者
Sub mac2()
Dim Col As Integer
Col = 1
Do While Cells(1, Col).Value <> ""
Cells(1, Col).Value = Left(Cells(1, Col).Value, InStr(Cells(1, Col).Value, "") - 1)
Col = Col + 1
Loop
End Sub