Screening values in cells to create a sentence..
Try this ........ change the sheet name to suit.....
Sub Sentence()
Dim xlr As Long, xr As Long, xSentence As String
With Sheets("Sheet1")
xlr = .Cells(.Rows.Count, 1).End(xlUp).Row
xSentence = "This store carries the following goods "
For xr = 1 To xlr
If Len(Trim(.Cells(xr, 1))) 0 Then
'use this value
If xr < xlr Then
xSentence = xSentence & Trim(.Cells(xr, 1)) & ", "
Else
xSentence = xSentence & " and " & Trim(.Cells(xr, 1)) & "...."
End If
End If
Next
End With
MsgBox xSentence
End Sub
--
Cheers
Nigel
"Ariel" wrote in message
...
I am trying to write a macro that will insert values from different cells
into a sentence. The problem is that not all cells will have a value in
them.
Do you have a suggestion that does this? Here's what I mean as an example:
Cell A1: paint
Cell B1: nails
Cell C1: null
Cell D1: screws
Cell E1: null
Here is the sentence:
This store carries the following goods: paint, nails, and screws....
As you can see from the example, I need to skip the cells with the null
values.
Any help would be much appreciated.
|