LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Array coding type mismatch

The Change Event code below works fine, except it is very slow as you would expect for a list in Column C of around 2000+ entries.

Trying to convert the Sub AP_by_State() to do the same as the event code.
It errors with a type mismatch as I have it now.

Entries are of this natu

Abilene, TX (ABI)
Abilene, TX (ABI)
Adak Island, AK (ADK)
Akiachak, AK (KKI)
Akiak, AK (AKI)
Akron/Canton, OH (CAK)
Akuton, AK (KQA)
Alakanuk, AK (AUK)
Alamogordo, NM (ALM)X
Alamosa, CO (ALS)

The state abbreviation is entered in cell B1 (TX for Texas, say) and all entries in column C with TX in them are highlighted.

AND

A list is compiled in column F of all those entries.

Using InStr() has risks of returning "Alamogordo, NM (ALM)" if OR for Oregon is the search string, but seem to be okay as long as the state abbreviation is uppercase and the user is aware of it.

Thanks.
Howard


Sub AP_by_State()
Dim varData() As Variant
Dim rngC As Range
Dim i As Long
Dim sAP As String

sAP = Range("B1")

With Sheets("State AP")
ReDim Preserve varData(sAP)
For Each rngC In .Range("C1:C" & Cells(Rows.Count, "C").End(xlUp).Row)
If InStr(rngC, sAP) 0 Then
varData(i) = rngC
i = i + 1
End If
Next

.Range("F1").Resize(UBound(varData) + 1, 1) = _
Application.Transpose(varData)
End With
End Sub


Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target < Range("B1") Then Exit Sub

Range("C:C").Interior.ColorIndex = xlNone
Range("F:F").ClearContents

Dim St As String
Dim c As Range

St = Range("B1")

For Each c In Range("C1:C" & Cells(Rows.Count, "C").End(xlUp).Row)

If InStr(c, St) 0 Then

c.Copy Range("F" & Rows.Count).End(xlUp)(2)
c.Interior.ColorIndex = 19 '15
End If

Next
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch: array or user-defined type expected Naftas Excel Programming 0 March 23rd 10 12:38 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM


All times are GMT +1. The time now is 11:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"