Concatinating cells

  • Thread starter Thread starter Praveen
  • Start date Start date
P

Praveen

Hi,

I am a newbie in VB and I was trying to code a funtion in it where it
concatinates all the elements in a row in 'sheetx' and make it into one
string and paste it into a row of 'sheety'.
Thus my code reads...

Sub Convert_Map_to_Text()

Dim sMap As String

For i = 5 To 24
For j = 2 To 80

sMap = sMap + Worksheets("Sheet3").Cells(i, j)
Next j

Worksheets("Sheet4").cell(i - 4, 1) = sMap
Next i


End Sub
--------------------

But I got the following error.

type run error 13
type Mismatch

Can some one point out why this is happening, and if possible a
solution for the same?

Thank you very much in advance.

Regards,
Praveen.
 
Hi Praveen,

The following worked for me

Sub Convert_Map_to_Text()

Dim sMap As String
Dim i As Long, j As Long

For i = 5 To 24
For j = 2 To 80

sMap = sMap + _
CStr(ActiveSheet.Cells(i, j).Value)
Next j
Worksheets("Sheet4").Cells(i, 1).Value = sMap
Next i

End Sub
 
Hi,
You have certainly removed the error. But since the Smap vaiable is not
getting cleared it will carying the whole string from the previous row
also.. I have to just look into that also...

Any way thanks a lot for the break through !!!
 
Hi Praveen,

Sub Convert_Map_to_Text2()

Dim sMap As String
Dim i As Long, j As Long

For i = 5 To 24
For j = 2 To 80

sMap = sMap + _
CStr(ActiveSheet.Cells(i, j).Value)
Next j
Worksheets("Sheet4").Cells(i, 1).Value = sMap
sMap = "" '<<==============
Next i

End Sub
 
THANKS Alot ... just now I did that. I got the same idea struck in my
head also. Thanks again...

Regards,
Praveen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top