現在業務で使うエクセルの表の分類・入力を楽にするために
「セルG12~G300orI12~I300のどれか一つに『携帯ショップスタッフor本社事務or審査事務』などの求人名を入力すると、H12~300orJ12~300の対応するセルに『時給1000円~1500円or月給16~18万円or月収23万』の給与額が入力される(例えばG12に入力をしたらH12に反映される)」というものを作成しています。
以下のコードを作成したのですが、入力をした求人名の順番通りに給与名が反映されず困っております。
Sub 求人内容ごとによる給与の振り分け非正規雇用() Dim v As Variant Dim i As Integer For i = 12 To 300 If Cells(i, 7) <> "" Then v = Application.Find("携帯ショップスタッフ", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = "時給1000円~1500円" End If v = Application.Find("本社事務", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("本社事務(オペレーター職)", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("秘書", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("業務部", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("コールセンター", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("インバウンド営業業務", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("会社名1", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("内部監査員", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("SHOP販売", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If v = Application.Find("CCC営業アシスタント", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "時給1100円" End If v = Application.Find("CCC庶務", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "時給1100円" End If v = Application.Find("審査事務(新卒)", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "時給1000円" End If v = Application.Find("審査事務(中途)", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "時給1100円" End If v = Application.Find("会社名2", Cells(i, 7)) If Not IsError(v) Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "時給1000円" End If End If Next End Sub Sub 求人内容ごとによる給与の振り分け正規雇用() Dim v As Variant Dim i As Integer For i = 12 To 300 If Cells(i, 9) <> "" Then v = Application.Find("新規開拓営業", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = "月給215000円" End If v = Application.Find("内部監査員", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給215000円" End If v = Application.Find("管理職", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給215000円" End If v = Application.Find("SHOP販売業務", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給215000円" End If v = Application.Find("インバウンド営業業務", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給215000円" End If v = Application.Find("データマイニング部", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給175000円" End If v = Application.Find("人事部", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給175000円" End If v = Application.Find("秘書", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給175000円" End If v = Application.Find("業務部", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給175000円" End If v = Application.Find("コールセンター", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給175000円" End If v = Application.Find("審査事務(新卒)", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給175000円" End If v = Application.Find("審査事務(中途)", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給205000円" End If v = Application.Find("CCC貿易業務及び通訳", Cells(i, 9)) If Not IsError(v) Then Cells(i, 10).Value = Cells(i, 10).Value & vbLf & "月給24~36万円" End If End If Next End Sub
この画像の、13の行が正しい並びなのですが、どうしても14の行の並びになってしまいます。数字の大小?の順に勝手に並ぶようになっているのでしょうか。
よろしくお願いします。
【追記 ttyp03さんの回答を反映したコードになります】
Sub 求人内容ごとによる給与の振り分け非正規雇用() Dim v As Variant Dim i As Integer For i = 12 To 300 If InStr(Cells(i, 7), "携帯ショップスタッフ") > 0 Then Cells(i, 8).Value = "時給1000円~1500円" End If If InStr(Cells(i, 7), "本社事務") > 0 Then Cells(i, 8).Value = "月給16~18万円" End If If InStr(Cells(i, 7), "CCC庶務") > 0 Then Cells(i, 8).Value = "時給1100円" End If Next End Sub
求人名を1つ入力し場合は問題なく給与が反映されます。
(本社事務→月給16~18万円と反映されています)
二つ以上入力しますと、うまく反映されません。(本社事務→月給16~18万円、携帯ショップスタッフ→"時給1000円~1500円と反映されるのが正しいです)
こちらも同じく
。(本社事務→月給16~18万円
、携帯ショップスタッフ→"時給1000円~1500円、CCC庶務→時給1100円と反映されるのが正しいです)
【追記2】
Sub 求人内容ごとによる給与の振り分け非正規雇用() Dim v As Variant Dim i As Integer For i = 12 To 300 If InStr(Cells(i, 7), "携帯ショップスタッフ") > 0 Then Cells(i, 8).Value = "時給1000円~1500円" End If If InStr(Cells(i, 7), "本社事務") > 0 Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "月給16~18万円" End If If InStr(Cells(i, 7), "CCC庶務") > 0 Then Cells(i, 8).Value = Cells(i, 8).Value & vbLf & "時給1100円" End If Next End Sub
このように前後してしまいます。(本社事務→月給16~18万円
、携帯ショップスタッフ→"時給1000円~1500円、CCC庶務→時給1100円と反映されるのが正しいです)
【追記】
ベストアンサーの方のコードを修正したものです
Sub 求人内容ごとによる給与の振り分け非正規雇用() Dim i As Integer For i = 12 To 300 jobs = Split(Cells(i, 7), vbLf) pays = "" For Each job In jobs Select Case job Case "携帯ショップスタッフ" pay = "時給1000円~1500円" Case "本社事務" pay = "月給16~18万円" Case "CCC営業アシスタント" pay = "時給1100円" pay = "" End Select If pay <> "" And pays <> "" Then pays = pays & vbLf End If pays = pays & pay Next Cells(i, 8).Value = pays Next End Sub
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/26 07:09
2017/04/26 07:11
2017/04/26 07:26
2017/04/26 07:31
2017/04/26 07:41
2017/04/27 08:18