PDA

View Full Version : Solved: String Concatenation to a cell



Sir Phoenix
10-05-2005, 03:09 PM
I'll post the code first here:

Private Sub addMe()

Dim schedFound, schedCell, schedRange As Range
Dim schedCount As Integer
Dim schedName As String

With ThisWorkbook.Sheets(4)
Set schedRange = .Range("a2", .Range("a65536").End(xlUp))
Set schedFound = schedRange.Find(Me.cmbSchedName.Value, MatchCase:=True)
End With
If schedFound Is Nothing Or Me.cmbSchedName.Value = "" Then
schedCount = 1
For Each schedCell In schedRange
If Left(schedCell.Text, Len(cmbSchedType.Value)) = schedCell.Text Then
schedCount = schedCount + 1
End If
Next schedCell
With ThisWorkbook.Sheets(4)
schedName = "" + Me.cmbSchedType.Value + schedCount
.Range("a" & schedRange.Count + 1).Value = schedName


It's erroring when I try to assign the value of the combobox concatenated with an integer to a string. I want to take this string and assign it to a cell, which I'm fairly sure will work once I can concatenate them correctly.

Thanks for all help!

TonyJollans
10-05-2005, 03:30 PM
I'm not quite sure what you're trying to do with the empty string literal, but you should use an ampersand (&) for string concatenation. Addition of strings using plus (+) is slightly different.

Sir Phoenix
10-05-2005, 05:29 PM
That worked! Closing thread.

johnske
10-05-2005, 07:02 PM
Hi Sir Phoenix,

Glad to see you've worked something out, you could also check out doing the concatenation as a function, see http://www.vbaexpress.com/kb/getarticle.php?kb_id=580

Regards,
John :)