• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro so that every cell in column B gets quote marks around entire string in the cell, not working

Hello,

I am tiring to write a macro so that every cell in column B gets quote marks around entire string in the cell.

My code places B2 in every cell in column B

Thanks for any help

Code:
Sub AddQuotes()
Dim rng As range, cell As range
Dim LastRow As Long
   
    With Sheets("sheet1")
        LastRow = .range("A" & .Rows.Count).End(xlUp).Row
    End With

Set rng = Sheets("Sheet1").range("B2:B" & LastRow)

For Each cell In rng
Worksheets("Sheet1").range("B2:B" & LastRow).Formula = "=" & Chr(34) & "B2" & Chr(34) & ""
Next

End Sub
 
Hi Tim,

Quick question, Do you have any values in column B and it is on these values that you want the quote marks?

As per your current code is set to put the value "B2" in all cells in column B.

Regards!!
 
Hi Tim ,

Try this :
Code:
Sub AddQuotes()
    Dim rng As Range, cell As Range
    Dim LastRow As Long
 
    With Sheets("sheet1")
        LastRow = .Range("A" & .Rows.Count).End(xlUp).Row

        Set rng = .Range("B2:B" & LastRow)

        For Each cell In rng
            cell.Value = Chr(34) & cell & Chr(34)
        Next
    End With
End Sub
Narayan
 
Back
Top