Thread: if elseif....
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default if elseif....

Hello again Steve

I think this is what you want:

If NewString = "" Then
NewString = MyRng.Cells(cell, 1).Value
ElseIf MyRng.Cells(cell, 1).Value < "" Then
NewString = NewString & vbLf & MyRng.Cells(cell, 1).Value
End If

Best regards,
Per

On 15 Jul., 23:55, SteveDB1
wrote:
Howdie all.

I have a macro that looks for the generic contents of a choosable number of
cells.

If it finds contents, it cuts those contents from each of the cells, it then
merges the cells chosen, and pastes the values from those cells into the
merged cell group.
Thus far it works well, but I would like to modify it.

Presently, the issue I'm facing is if there are any blank cells, it inputs a
vbLf, or chr(10) input for those cells.

What I'd like to do is- if a cell is blank, I do not want a character line
return placed there.

The code for this macro is:
-----------------------------------------------------------------
Dim myRng As Range
Dim NewString As String

Set myRng = Nothing
On Error Resume Next
InputRange:
Set myRng = Application.InputBox(prompt:="Select cells to Meld", Type:=8)
If myRng Is Nothing Then End

If myRng.Cells.count 8 Then
* * msg = MsgBox("Invalid range selection" & vbLf & vbLf & "Please try
again", vbExclamation, "Regards, Per Jessen")
* * GoTo InputRange
End If

For cell = 1 To myRng.Cells.count

* * If NewString = "" Then
* * * * NewString = myRng.Cells(cell, 1).Value
* * Else
* * * * NewString = NewString & vbLf & myRng.Cells(cell, 1).Value
* * * * * * 'this NewString allows a character return to have a new line.
'here is where I think that my modification should occur.
'I don't want rows at the end of my cell contents to be counted if there
' are no contents there. *
'Elseif newstring or cell = "" then
'do not include.

* * End If

* * myRng.Cells(cell, 1).ClearContents
*Next

myRng.Cells(1, 1) = NewString
myRng.MergeCells = True
myRng.WrapText = True
myRng.HorizontalAlignment = xlCenter
myRng.VerticalAlignment = xlCenter
----------------------------------------------------------------

E.g. I have 4 rows.
Rows 1, and 2 have some generic contents as text. Rows 3 and 4 have nothing
in them.
I want to only include rows one and two, but then am going to merge all 4
rows.

Thank you for your helps.
Best.