私は作成した1番目の配列に書き込む文字数が限られているので、列にリストされている都市/可能な都市の数を数えるマクロを作成しようとしています。その通り)。 その後、2番目の配列でDim Cities2()を追加しましたが、「型の不一致エラー」というエラーが表示されました。助けてください。 Btw、私はまだアレイリストに200以上の都市を追加する必要があるが、それらをまだ追加していない。お手伝いありがとう。mutilpleマクロを組み合わせる
Public Sub CountLocation1()
Dim wb As Workbook
Dim ws As Worksheet
Dim lastCell As String
Dim countRange As Range
Set wb = ThisWorkbook
Set ws = wb.ActiveSheet 'Change as appropriate
Set countRange = ws.Range(Cells(2, "V"), Cells(ws.Range("V2").End(xlDown).Row, "V"))
Debug.Print countRange.Address
Dim Cities()
Cities = Array("Auckland", "Brisbane", "Melbourne", "Seoul", "Tokyo", "Sydney", "Bratislava", "Bangalore", "Chennai", "Gurgaon", "Hyderabad", "Kolkata", "New Delhi", "Noida", "Mumbai", "London", "Munich", "Unterfohring", "Aachen", "Abidjan", "Abington", "Alpharetta", "Amstelveen", "Amsterdam", "Anaheim", "Aquascalientes", "Arlon", "Ashland", "Atlanta", "Aurora", "Austin", "Barcelona", "Basel", "Batavia", "Bay Village", "Belton", "Berkshire", "Berlin", "Birmingham", "Bogota", "Boise", "Boston", "Bramley", "Brandon", "Brecksville", "Brentwood", "Bridgetown", "Brussels", "Budapest", "Buffalo Grove", "Bury", "Cairo", "Callahan", "Calumet City", "Cape Town", "Capitola", "Cardiff", "Carmel", "Centennial", "Chanhassen", "Charlotte", "Cheltenham", "Cincinnati", "Clearwater", "Clemson", "Cleveland", "Cohoes", "Columbia", "Columbus", "Conifer", "Cookeville", "Copenhagen", "Coral Gables", "Croydon", "Culver City", "Cumming", "Cutchogue", "Dallas", "Dallas Park", "Darmstadt", "Double Oak", "Dublin")
Dim Cities2()
Cities2 = Array("Eagle Rock", "East Hartford", "Elk Grove", "Encino", "Enfield", "Erfurt", "Eschborn", "Euless", "Fairfield", "Fenton", "Folkestone", "Folsom", "Frankfurt", "Franklin", "Frisco", "Garden City", "Geneva", "Germantown", "Glendale", "Glenview", "Gloucester", "Greensboro", "Greenwood", "Greenwood Village", "Grove", "Hamburg", "Hamilton", "Harrisonville", "Hartford", "Hatfield", "Hiawatha", "Hitchin", "Hofstetten", "Homewood", "Hope", "Houston", "Hudson", "Illinois", "Indianapolis", "Itasca", "Jackson", "Jacksonville", "Jaipur", "Johannesburg", "Jordbro", "Katy", "Kirkwood", "Ladera Ranch", "Lake Forest", "Lakewood", "Lancaster", "Largo", "Lawrenceville", "Leawood", "Lexington", "Liberty", "Lincoln", "Lockport", "Lombard", "Luxembourg", "Lörrach", "Madrid", "Manchester", "Maple Glen", "Martins Ferry", "Marupe", "Masontown", "Matthews", "McKinney", "Mechanicsville", "Middletown", "Milan")
Dim city As Long
Dim counter As Long
Dim startRange As Range
Set startRange = ws.Cells(ws.Range("V2").End(xlDown).Row, "V").Offset(2, 0)
counter = 2
For city = LBound(Cities, Cities2) To UBound(Cities, Cities2)
If Application.WorksheetFunction.CountIf(countRange, Cities(city)) > 0 Then
startRange.Offset(counter, 0) = Application.WorksheetFunction.CountIf(countRange, Cities, Cities2(city))
startRange.Offset(counter, 1) = Cities & Cities2(city)
counter = counter + 1
End If
Next city
End Sub
'LBOUND()'と 'UBound関数は、()'パラメータとして単一の配列を取ることができます2つを通過しました。これらは分離する必要があります。 –
For city = LBound(都市)をUBound(都市)に&city = LBound(都市2)にUBound(都市2)に使用できますか? – Jonathan
これは好きではありません。ネストされたループを作成することはできますが、コメントセクションで説明することは難しいです。 –