我真的很难将下面的excel公式转换为VBA。我认为下面的函数需要位于for循环内,并且需要向下降低动态列长度。我一直在寻找尝试自己编写脚本的方法,但是似乎无法正确运行它。
= MID(A1,FIND(“:”,A1)+ 1,FIND(“(”,A1)-FIND(“:”,A1)-1)
您可以使用以下方法动态获取列长(或最后一行):
dim ws as Worksheet
Set ws = Thisworkbook.Worksheets("mySheetNameHere")
dim lastRow, myLoop, semicolPos, bracketPos
lastRow = ws.Cells(ws.rows.count, "A").End(xlUp).Row ' this gets last row in col A
For myLoop = 1 to lastRow
' Find the position of the ";" and the "("
semicolPos = InStr(ws.Range("A" & myLoop).Value, ":") + 1
bracketPos = InStr(ws.Range("A" & myLoop).Value, "(")
newValue = Mid(ws.Range("A" & myLoop).Value, semicolPos, bracketPos - semicolPos)
' Put newValue into column B, one cell over from column A
ws.Range("B" & myLoop).Value = newValue
Next
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句