VBA Error 2029 Mismatch Type

TylerCross

New Member
Joined
Jan 5, 2021
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
Hello,
I am currently creating some vba code to concatenate rows in a certain column into one. When I run two different data, the first one works but then the second one does not work and I receive a error message. My code is
Sub mergeCategoryValues()
Dim lngRow As Long

With Sheet1
Dim columnToMatch As Integer: columnToMatch = 1
Dim columnToConcatenate As Variant: columnToConcatenate = 22
Dim columnToSum As Integer: columnToSum = 2

lngRow = .Cells(65536, columnToMatch).End(xlUp).Row
.Cells(columnToMatch).CurrentRegion.Sort key1:=.Cells(columnToMatch), Header:=xlYes

Do
If .Cells(lngRow, columnToMatch) = .Cells(lngRow - 1, columnToMatch) Then
.Cells(lngRow - 1, columnToConcatenate) = .Cells(lngRow - 1, columnToConcatenate) & "; " & .Cells(lngRow, columnToConcatenate)
.Cells(lngRow - 1, columnToSum) = .Cells(lngRow - 1, columnToSum) + .Cells(lngRow, columnToSum)
.Rows(lngRow).Delete
End If

lngRow = lngRow - 1
Loop Until lngRow = 1
End With
MsgBox (" Macro Complete! ")

End Sub

The red text is where the error is occurring. I am using a Variant data type in the rows it contains numbers and text.
Any help is greatly appreciated.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
When you get the error what's actually in the cells you are trying to concatenate?
 
Upvote 0
I think I would declare 'columnToConcatenate' as a long integer rather than variant:
VBA Code:
Dim columnToConcatenate As Long
and then add .Value to the cell references you are concatenating.
VBA Code:
.Cells(lngRow - 1, columnToConcatenate) = .Cells(lngRow - 1, columnToConcatenate).Value & "; " & .Cells(lngRow, columnToConcatenate).Value
 
Upvote 0
When you get the error what's actually in the cells you are trying to concatenate?
I am using the first column as the "transaction number" If there are multiple items it will have more then one row with the same transaction number, column 22 is "text notes" so it could either provide a reason why there is a transaction or a receipt number
 
Upvote 0
Are there any errors in the columns you trying to concatenate?
 
Upvote 0
Are there any errors in the columns you trying to concatenate?
.Cells(lngRow - 1, columnToConcatenate) = Error 2029
This is the error that occurs on the Concatenate line.
When looking at the column there is not but when applying a filter there is #NAME?
 
Upvote 0
The #NAME? is the problem, you can't concatenate an error value with another value.
 
Upvote 0
The #NAME? is the problem, you can't concatenate an error value with another value.
Thank you for your help. Do you know why this error is occurring. When selecting this the #NAME? no data appears in any of the columns.
 
Upvote 0
What's the formula in the cell that's showing #NAME? ?
 
Upvote 0

Forum statistics

Threads
1,223,923
Messages
6,175,399
Members
452,640
Latest member
steveridge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top