Solved

Concatenate in vba give "type mismatch" error

Posted on 2014-11-26
6
194 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

746 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

10 Experts available now in Live!

Get 1:1 Help Now