これらの領域をこれらの領域に分割して新しい列を作成するためのExcel in Macrosを作成しようとしています。私は実行時エラー13を取得し続けるExcelマクロヘルプ。配列に基づいて新しい列を作成する。
これまでのコードはここにあります。
Sub Region()
Dim Pacific As Variant
Pacific = Array("WA", "OR", "ID", "CA", "NV", "AZ", "NM", "HI", "AK")
Dim Continental As Variant
Continental = Array("AR", "IA", "CO", "KS", "LA", "MS", "MT", "ND", "NE", "OK", "SD", "UT", "WY")
Dim SouthEast As Variant
SouthEast = Array("GA", "AL", "FL", "SC", "KY", "TN")
Dim Midwest As Variant
Midwest = Array("MN", "WI", "IL", "IN", "MI", "OH")
Dim NorthAtlantic As Variant
NorthAtlantic = Array("ME", "NH", "MA", "RI", "CT", "VT", "NY", "PA", "NJ", "DE", "MD", "WV", "VA", "NC")
Dim Texas As Variant
Texas = Array("TX”)
Dim state As String , result As String
score = Range("F1").Value
If state = Pacific Then
result = "PACIFIC"
ElseIf state = Continental Then
result = "Continental"
ElseIf state = SouthEast Then
result = "SouthEast"
ElseIf state = Midwest Then
result = "Midwest"
ElseIf state = NorthAtlantic Then
result = "North Atlantic"
ElseIf state = Texas Then
result = "Texas"
Else
result = "fail"
End If
Range("Z1").Value = result
End Sub
ありがとうございました!これはチャームのように機能しました! –
もう少し質問があります。これを列全体に適用するにはどうすればよいですか? –
@TimothyYelverton - ループを示すために答えが更新されました – YowE3K