从句子中返回最后一个单词

尝试获取I / O如下:

Col B is input Col C will get output 1 ABC DEF JKH JKH 2 KJJB ljac Kjb Kjb 3 jabcl sjac casc casc . . 

但是我把第11行的错误看作是“无效的程序调用或参数”:

  Option Explicit Sub seperate() Dim strarr() As String Dim str As String Dim i, j As Integer Dim k As Long Dim ws As Worksheet Set ws = Sheets("Main") k = ws.Range("B1048576").End(xlUp).Row For i = 1 To k str = Cells("i,B").Value 'Error here as Invalid proc call or argument strarr() = Split(str) j = UBound(strarr()) Cells("i,C").Value = strarr(j) Next i End Sub 

干得好。

 Sub Santosh() Dim i&, v, w v = Worksheets("Main").[b1:index(b:b,match("*",b:b,-1))].Value For i = 1 To UBound(v) w = Split(v(i, 1), " ") v(i, 1) = w(UBound(w)) Next Worksheets("Main").[c1].Resize(UBound(v)) = v End Sub 

考虑:

 Option Explicit Sub separate() Dim strarr() As String Dim sttr As String Dim i As Long, j As Long Dim k As Long Dim ws As Worksheet Set ws = Sheets("Main") k = ws.Range("B1048576").End(xlUp).Row For i = 1 To k sttr = Cells(i, "B").Text strarr = Split(sttr) j = UBound(strarr) Cells(i, "C").Value = strarr(j) Next i End Sub 

str = Cells(“i,B”)。值'错误在这里作为无效的proc调用或参数

错误的语法。 应该是Range("B" & i)Cells (i, "B")