• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:VBAでのデータの結合)

VBAでのデータの結合

WWolfの回答

  • ベストアンサー
  • WWolf
  • ベストアンサー率26% (51/192)
回答No.1

こんにちは やりたいことがコードを見るといまいち把握しきれていないのですが >Form上で、3つのComboBoxに入力(選択)した値を結合させるため なら・・・ Lbl開始年月日.Caption = mykc1 & mykc2 & mykc3 です。 開始と終了が同じ年月日なのが??で・・・補足があればよろしく

chibii
質問者

お礼

回答ありがとうございます。 試してみたところ、無事に動きました。 「&」でつながってしまうって言うシンプルさにちょっとビックリしましたが・・・(^-^;) ちなみに、 1行目 → 検索キー 2行目 → 開始年月日 3行目 → 終了年月日 の順でデータが入力されているので、 Lbl開始年月日.Caption = Application.WorksheetFunction. _ VLookup((mykc1 & mykc2 & mykc3), Range("検索"), 2, False) Lbl終了年月日.Caption = Application.WorksheetFunction. _ VLookup((mykc1 & mykc2 & mykc3), Range("検索"), 3, False) としてみて成功しました。 本当にありがとうございました。

関連するQ&A

  • EXCEL VBA:結合セルのデータを取り出すには?

    結合セルに書き込まれている文字列を取得したいのですが、 何か良い方法はありますか? 以下のような方法をとってみたのですが、 イマイチうまくいきませんでした。。。 Dim iRow as Integer Dim strData as String iRow = 1 strData = Cells(iRow, 1).MergeArea.Value どなたかご教授頂けないでしょうか? 何卒よろしくお願いします。

  • エクセルファイルの有効期限の設定について

    エクセルのファイルに有期限を設定し、期日が来たら特定の "Seet"を削除してしまい、利用に値しない物にする。 このようなプログラムを作りたいのですが、他の方の質問を 参考に、流用して、いろいろやってみたのですが、どうもうまく行きません。 どなたかお知恵をお貸しください。 よろしくお願いたします。 This Workseet Openのプログラム中には、次の構文が入っています。 メッセージBOXを表示するまではうまく行きましたが、それ以降で 行き詰まっております。 ----------------- Private Sub Workbook_Open() Dim i As Integer, j As Integer, k As Integer Dim Start As Integer, Finish As Integer Dim Lbl As Variant Dim Cmb(4) As ComboBox Lbl = Array("札幌", "函館", "福島", "新潟", "東京", "中山", "中京", "京都", "阪神", "小倉") With Sheet1 .ListBox1.Clear .ListBox1.Font.Size = 10 For i = 0 To 9 .ListBox1.AddItem Lbl(i) Next .ListBox1.ListIndex = 4 Set Cmb(1) = .ComboBox1: Set Cmb(2) = .ComboBox2 Set Cmb(3) = .ComboBox3: Set Cmb(4) = .ComboBox4 Lbl = Array("", "開催年", "開催月", "開催日", "発走") For i = 1 To 4 Cmb(i).Clear Cmb(i).Font.Size = 10 Cmb(i).AddItem Lbl(i) Next Select Case Sheet1.Range("E4") Case 2003 To 2999: Start = Sheet1.Range("E4") Case Else: Start = 2003 End Select Select Case Sheet1.Range("F4") Case 2003 To 2999: Finish = Sheet1.Range("F4") Case Else: Finish = 2003 End Select k = 0 For i = Start To Finish k = k + 1 .ComboBox1.AddItem i If .ComboBox1.List(k) = Format(Date, "yyyy") Then .ComboBox1.ListIndex = k End If Next For i = 1 To 12 .ComboBox2.AddItem Format(i, "00") Next For i = 1 To 31 .ComboBox3.AddItem Format(i, "00") Next For i = 1 To 12 .ComboBox4.AddItem Format(i, "00") Next .ComboBox2.ListIndex = Month(Date) .ComboBox3.ListIndex = Day(Date) .ComboBox4.ListIndex = 1 End With MsgBox ("使用期限は 2009/9/18です")

  • VBAの変数について

    VBAでUserFormからデータを入力します。 入力された各データをTarget1~Target20に代入します。 各Targetにデータが入っている場合は、配列K(i)に「1」を格納します。 そこで、Target "1"~"20" を変数iであらわしたいのですが、どのように表現したらよいのでしょうか。 Dim i As Integer Dim K(20) As Integer Target1 = TextBox1.Value Target2 = ComboBox1.Value : : Target19 = TextBox12.Value Target20 = ComboBox8.Value For i = 1 To 20 If 『  ?   』 <> "" Then K(i) = 1 EndIf Next i

  • VBAの簡略化について

    VBAで数値をカウントするマクロを作りました。  Dim Co1 As Integer Co1 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<1") Dim Co2 As Integer Co2 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<2") Dim Co3 As Integer Co3 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<3") Dim Co4 As Integer Co4 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<4") Dim Co5 As Integer Co5 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<5") Dim Co6 As Integer Co6 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<6") Dim Co7 As Integer Co7 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<7") Dim Co8 As Integer Co8 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<8") Dim Co9 As Integer Co9 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<9") Dim Co10 As Integer Co10 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), "<10") Dim Co11 As Integer Co11 = WorksheetFunction.CountIf(Range(Cells(○, ○), Cells(○, ○)), ">=10") Cells(2, 1) = Co1 Cells(3, 1) = Co2 - Co1 Cells(4, 1) = Co3 - Co2 Cells(5, 1) = Co4 - Co3 Cells(6, 1) = Co5 - Co4 Cells(7, 1) = Co6 - Co5 Cells(8, 1) = Co7 - Co6 Cells(9, 1) = Co8 - Co7 Cells(10, 1) = Co9 - Co8 Cells(11, 1) = Co10 - Co9 Cells(12, 1) = Co11 Cells(2, 1) = "0~0.999" Cells(3, 1) = "1~1.999" Cells(4, 1) = "2~2.999" Cells(5, 1) = "3~3.999" Cells(6, 1) = "4~4.999" Cells(7, 1) = "5~5.999" Cells(8, 1) = "6~6.999" Cells(9, 1) = "7~7.999" Cells(10, 1) = "8~8.999" Cells(11, 1) = "9~9.999" Cells(12, 1) = "10~" これを短くする方法を教えてください。

  • エクセル VBA OptionButtonからTextBox

    すいません! OptionButtonなら 下記の記述でエラー表示を 簡単にできるのですが これがOptionButtonではなく TextBoxならどのように変化したら 良いのでしょうか? すいません、教えて下さい! Private Sub 記録_Click() Dim i As Integer Dim Cnt As Integer Cnt = 0 For i = 1 To 6 Step 1 If Me.Controls("OptionButton" & i).Value Then Cnt = i Exit For End If Next i If Cnt = 0 Then MsgBox "選択されていません" Exit Sub End If If Me.Controls("Combobox" & Cnt).Value = "" Then MsgBox Me.Controls("OptionButton" & Cnt).Caption & " の内容が選択されていません" Exit Sub End If With 記入フォーム .TextBox5.Value = Me.Controls("OptionButton" & Cnt).Caption .TextBox6.Value = Me.Controls("Combobox" & Cnt).Value End With Unload Me End Sub

  • VBA VLOOKUP 別のファイルを参照

    VBA VLOOKUP 別のファイルを参照 いつもこちらでお世話になっている者です。 VBAの勉強をしております。 別のファイルからVLOOKUPで値を参照したいのですが、 範囲を指定してみましたが、 「worksheetFunctionクラスのVlookupプロパティを参照できません」 とのメッセージが出てしまいます。 なお、値は空白になる行もありますので、 if関数で回避してみましたがうまくいきません。 いろいろ試しましたが、何度やってもうまくいかないので こちらに質問させていただきました。 お詳しい方、ご伝授いただければ助かります。 よろしくお願い致します。 環境はExcel2007です。 Sub sample() Dim 範囲 As Range Dim wb As Workbook, wb2 As Workbook Dim r As Integer,intRow As Integer Workbooks.Open Filename:="***.xlsm" Set wb = ThisWorkbook Set wb2 = ActiveWorkbook Set 範囲 = wb2.Sheets("PvtSht2").Range("Database3") r = wb.Sheets("sheet1").Range("A28:N28").End(xlToRight).ColumnintRow = 3 With wb.Sheets("sheet1") Do Until .Cells(intRow, 1).Value = "" .Cells(intRow, (r + 1)) = Application.WorksheetFunction.If((Application.WorksheetFunction.VLookup(Cells(intRow, 1), 範囲, 2, False)) = 0, "", Application.WorksheetFunction.VLookup(Cells(intRow, 1), 範囲, 2, False)) intRow = intRow + 1 Loop End With End sub

  • VBAでVlookup関数を組もうとしていますがエラーが出ます。VBAに詳しい方、教えてください

    VBAでvlookup関数を下のように組みましたが、(1)でエラーが出ます。VBAに詳しい方、教えてください。 Sub VLLOKUPによる表の検索4() Dim mykensakuchi Dim mykensakuhan Dim gyo As Integer (1) mykensakuchi = Worksheets("sheet1").Range("a" & gyo).Value mykensakuhan = Worksheets("sheet2").Range("b2:e9") saikagyo = Worksheets("sheet1").Range("a" & Rows.Count).End(xlUp).Row gyo = 2 For gyo = saikagyo To 1 Step -1 With Application.WorksheetFunction Range("b:gyo").Value = .VLookup(mykensakuchi, mykensakuhan, 2, False) End With Next End Sub

  • VBA 初心者

    sheet1から、sheet2データを検索して抽出する練習をしているのですがerror"1104"が表示されます、なぜなのか分からないので投稿しました、よろしくお願いします。 sub test() dim sh1 as worksheets dim sh2 as worksheets dim  i  as  integer set sh1 = thisworkbook.worksheets("sheet1!") set sh2 = thisworkbook.worksheets("sheet2!") b = userform1.textbox1 for i = 1 to 10 sh1 .cells(i,2) = b b = b+1 x = sh1.cells(1,2) sh1.cells(i,3).value = worksheetfunction.vlookup(x,sh2.range("a1:d500"),2,false) next i end sub

  • VBAのComboBoxについて

    UserForm1にComboBoxが8個(ComboBox1~8)あります。 各ComboBoxはSheet1の下記列に入力されているリストを表示します。 ComboBox1 : A列 ComboBox2 : B列 ComboBox3 : C列 ComboBox4 : D列 ComboBox5 : E列 ComboBox6 : F列 ComboBox7 : G列 ComboBox8 : H列 ComboBox9 : I列 ComboBox10 : J列 そこで、UserForm1の各ComboBoxでデータ選択する際に、リストにある場合はそれを選択し、リストにない場合はComboBoxに新しいデータを入力し、UserForm1のCommandButton1を押下時にその新しいデータをSheet1の各列に追加したいのですが、どのようにしたらよいのでしょうか。 Sheet1にあるリストをComboBoxに表示するところまではできています。 ※ComboBoxの番号とリストの列番号を一致させています。 --------------------------------------------------------------- Private Sub UserForm_Initialize() Dim lastrw As Integer, retu As Integer, i As Integer For retu = 1 To 10 lastrw = Sheet1.Cells(1, retu).End(xlDown).Row For i = 1 To lastrw - 1 Controls("ComboBox" & retu).AddItem Sheet1.Cells(i + 1, retu).Value Next i Next retu End Sub ---------------------------------------------------------------

  • VBAの得意な方、教えてください(初心者です)

    エクセルのシートが セルA1に1 セルA2に2 セルA3に3 セルA4に4 セルA5に5 という数字が入っています。 で、セルD4には"=D2*5"という数式が入っています。 セルD2にA1の数値を代入して、出てきた数値をB1に入力、 次にD2にA2の数値を代入して、出てきた数値をB2に入力…以下続く というのをVBAで書いてみたら、下のような感じになりました。 Sub test() Dim d1 As Integer Dim d2 As Integer Dim d3 As Integer Dim d4 As Integer Dim d5 As Integer Dim p1 As Integer Dim p2 As Integer Dim p3 As Integer Dim p4 As Integer Dim p5 As Integer d1 = Cells(1, 1).Value Cells(2, 4).Value = d1 p1 = Cells(4, 4).Value Cells(1, 2).Value = p1 d2 = Cells(2, 1).Value Cells(2, 4).Value = d2 p2 = Cells(4, 4).Value Cells(2, 2).Value = p2 d3 = Cells(3, 1).Value Cells(2, 4).Value = d3 p3 = Cells(4, 4).Value Cells(3, 2).Value = p3 d4 = Cells(4, 1).Value Cells(2, 4).Value = d4 p4 = Cells(4, 4).Value Cells(4, 2).Value = p4 d5 = Cells(5, 1).Value Cells(2, 4).Value = d5 p5 = Cells(4, 4).Value Cells(5, 2).Value = p5 End Sub ここで質問です。 例では5個しかないのですが、実際は100行くらいのデータなんで 大変です。もっと簡単にする方法はありますか? 実際のセルD4の数式は、他からも参照したりしているので、 ここはいじらずに教えてください。 Excel2000、Visual Basic 6.0 ってのを使っています。 よろしくお願いいたします。