Search code examples
excelvbaxls

how to add a slash to all the lines content in the excel?


image
UploadPic/2012-02-08/132168689584.jpg
UploadPic/2012-02-08/132168689539.jpg
UploadPic/2012-02-08/132168689579.jpg
UploadPic/2012-02-08/132168689580.jpg
UploadPic/2012-02-08/132168689659.jpg
UploadPic/2012-02-08/132168689698.jpg
UploadPic/2012-02-08/132168689611.jpg
UploadPic/2012-02-08/132168689621.jpg
UploadPic/2012-02-08/132168689610.jpg
UploadPic/2012-02-08/132168689658.jpg

there is a column (img)like the above, now i want to add a slash before UploadPic(/UploadPic) and do it with a batch. how do i do?


Solution

  • This simple little macro will do that to every used cell in column A:

    Sub AddSlash()
    Dim MyRNG As Range, cell As Range
    
    Set MyRNG = Range("A:A").SpecialCells(xlConstants)
    
        For Each cell In MyRNG
            cell.Value = "/" & cell.Value
        Next cell
    
    End Sub
    

    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.