http://imgur.com/ekrjv0D
Hi please check above image. Is there any way to insert number before each word in worksheet.
I have a table like this:
Try this short macro:
Sub marine()
Dim n As Long
Dim r As Range
n = 1
For Each r In ActiveSheet.UsedRange
If r.Value <> "" Then
r.Value = n & "/" & r.Value
n = n + 1
End If
Next r
End Sub
another additional variant to already posted:
Sub test()
Dim cl As Range, i&
Set cl = Cells.Find("*")
For i = 1 To WorksheetFunction.CountA(Cells)
If Not cl Is Nothing Then
cl.Value2 = i & "/" & cl.Value2
Set cl = Cells.FindNext(cl)
Else
Exit For
End If
Next i
End Sub
updated against additional question:
Is there anyway to remove back the numbers and slash at the beginning of each word
you can use this:
Sub test2()
Dim n&, r As Range: n = 1
For Each r In ActiveSheet.UsedRange
If r.Value2 Like "*/*" Then
r.Value2 = Split(r.Value2, "/")(1)
n = n + 1
End If
Next r
End Sub