Hi Mahesh,

I have removed the .select from your code, I have not tested it so let me know if it works.

Code

- Sub test()
- Dim Querystring As String
- Dim Rng As Range, InvalidRng As Range
- Dim ws As Worksheet: Set ws = Sheets("WA1Result")
- LastRow = ws.Cells(Rows.Count, 17).End(xlUp).Row
- For Each Rng In ws.Range("Q2:Q" & LastRow)
- If Rng = "No" Then
- ws.Cells(Rng.Row, Rng.Column - 4).NumberFormat = "@"
- Querystring = ws.Cells(Rng.Row, Rng.Column - 4)
- MsgBox Querystring
- End If
- Next Rng
- End Sub

Also note that your method for declaring variables needs to be in full:

Dim rng, Invalidrng as Range results in rng being declared a variant not a range, it should be Dim rng as range, InvalidRng as range

As Jolivanes above is indicating, do not forget to wrap your code.

Justin