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.
 
You wouldn't get #NAME? in a cell unless it had a formula in it.

Where exactly is it appearing?
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Out of curiosity, what is the value of "lngRow" when the error occurs?
 
Upvote 0

Forum statistics

Threads
1,223,927
Messages
6,175,431
Members
452,641
Latest member
Arcaila

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