Solved

Concatenate in vba give "type mismatch" error

Posted on 2014-11-26
6
201 Views
Last Modified: 2014-11-26
HI Guys,
Adding some VBA code to my spreadsheet, but cannot seem to make it work:

I'm trying to concatenate two cells like this:

    Dim eSpk(20), eAss(20), eLsn(20), eEvl(20) As String
    . . . 
                eSpk(i) = e0.Offset(0, 1).Value
                eAss(i) = e0.Offset(0, 2).Value
                eLsn(i) = "#" & e0.Offset(0, 3).Value & " " & e0.Offset(0, 4).Value
                eEvl(i) = e0.Offset(0, 5).Value
   . . . 

Open in new window

And gives "Type" mismatch.
I'm sure you experts have the solution to this somewhat basic question.
Thanks.
0
Comment
Question by:MikeOM_DBA
  • 4
  • 2
6 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 40467602
Do any of the cells you want to concatenate contain error values?
0
 
LVL 29

Author Comment

by:MikeOM_DBA
ID: 40467626
No.
If I put the "sub" in it's own module, it works when executed by itself
But if I call from another module it breaks.
here is some more code:
. . .
    Sheets("EmailMM").Activate
    For Each e0 In ActiveSheet.Range("MMemail").Cells
        k = e0.Row
        If k > 1 And e0.Value <> "" Then
            eTo = eTo & e0.Value & ";"
            If e0.Offset(0, -5).Value <> "E" Then
                i = i + 1
                eSpk(i) = e0.Offset(0, 1).Value
                eAss(i) = e0.Offset(0, 2).Value
                eLsn(i) = "#" & e0.Offset(0, 3).Value & " " & e0.Offset(0, 4).Value
                eEvl(i) = e0.Offset(0, 5).Value
            End If
        End If
    Next e0

Open in new window

0
 
LVL 29

Author Comment

by:MikeOM_DBA
ID: 40467638
Found it...

Put the procedure in separate module and call it from main module worked!

Spent almost 2 days debugging.

Thanks anyway for looking into it.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 29

Author Comment

by:MikeOM_DBA
ID: 40468196
I've requested that this question be closed as follows:

Accepted answer: 0 points for MikeOM_DBA's comment #a40467638
Assisted answer: 100 points for imnorie's comment #a40467602

for the following reason:

Did not find the cause, but now it works...
0
 
LVL 33

Expert Comment

by:Norie
ID: 40467666
Glad you got it working.:)

What happens if you change the code to use an explicit sheet reference like this.
For Each e0 In Sheets("EmailMM").Range("MMemail").Cells

Open in new window

0
 
LVL 29

Author Comment

by:MikeOM_DBA
ID: 40468205
PS: The cause was the relocation of a named range which had absolute ($xx) addressing which then invalidated dependent locations.
Thanks for the tip.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now