EXACT same code pieces -- different reactions

CWMacNut

New Member
Joined
Dec 28, 2018
Messages
11
I have two pieces of code. They are both subroutines. They have the exact same coding up to a certain point but the 2nd one is giving me a "type mismatch" error. I don't see why it's reacting differently to the EXACT same coding!!

Code:
Sub DeleteSeqCol[COLOR=#ff0000][B](HeaderCount%, HeaderNames As Variant)
        Range("A1").Select
        a = 1  ' ("A1")
        For a = 1 To HeaderCount
                If HeaderNames(a) = "[/B][/COLOR]seq" Then
                        Range(Selection, Selection.End(xlDown)).Select
                        Selection.Delete Shift:=xlToLeft
                        Selection.ColumnWidth = 7  ' .AutoFit
                        Exit For
                End If
        Next
End Sub

Sub SortToVersion[COLOR=#ff0000][B](HeaderCount%, HeaderNames As Variant)
        Range("A1").Select
        a = 1  ' ("A1")
        For a = 1 To HeaderCount
                If HeaderNames(a) = "[/B][/COLOR]sort" Then   [COLOR=#008000][B]<-------- this line is getting a "Type Mismatch" error[/B][/COLOR]
                        Selection.Offset(0, a).Select
                        Range(Selection, Selection.End(xlDown)).Select
                        Selection.ColumnWidth = 7
                        Selection.ClearContents
                        Selection.Offset(0, 1).Select
                        Selection.Offset(0, -1).Select
                        ActiveCell.FormulaR1C1 = "version"
                        Exit For
                End If
        Next
End Sub

I've highlighted the code that is EXACTLY the same.

I promise that I researched this question before posting. I couldn't find a similar problem.

Thank you,
CWMacNut
Graphics Engineer
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Verify the values you are feeding them in your arguments.

Note that if "HeaderNames" is an array, by default, arrays are zero-based in VBA.
So you would want to start with a=0 (and you might need to change how the code cycles through the array).

If you cannot figure it out, please let us know the values that are being passed in for each one.
 
Last edited:
Upvote 0
Does "sort" come after "seq" in your array?
If so do you have any error values in you Header like #N/A, #NA Me etc?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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