連続されたデータの最終行を知る!
ExcelVBAはエディタがしょぼっくてめんどい。
補填を全部してくれないし・・・ヾ(▼ヘ▼;)
でも、やっている最中なんですけど 何か?(・ε・)
さて、あるリストをもらったんだけど、それをワンクリックで一定の項目で並べ替えてくれって言われちゃったよ。。。(む~り~。(´д`lll) )
でもやりました。
リストはどこまであるのっていうCountをしたかったので、
こんなに便利な書き方を見つけました。
教えてくれたサイト(ありがとう)
http://www.happy2-island.com/
ActiveSheet.Cells(Row,Column).End(xlDown).Row
一発ででてきました。。。( ̄□ ̄;)!!すげっ
世の中なんでもぐぐったら見つかる!!いい世の中だ・・・
作ったVBEものせとこ
Private Sub test()
Dim ThisSheet As Worksheet
Dim I As Integer, J As Integer
Dim LastCnt As Long
Dim RowCnt As Long
Dim NumRow As Long
’余分な文字があるので、Replaceしちゃうぞ
Const Name As String = "名称:"
Const Service As String = "サービス:"
Const Number As String = "番号:"
Const Post As String = "郵便番号:"
Const TEL As String = "電話:"
Const FAX As String = "ファクス:"
Dim ID As Integer
Dim StrName As String
Dim StrService As String
Dim StrNumber As String
Dim StrPost As String
Dim StrAddress As String
Dim StrTel As String
Dim StrFax As String
Set ThisSheet = ActiveSheet
’ここ!で使いました。
LastCnt = ThisSheet.Cells(1, 4).End(xlDown).Row
’6行ずつ2列で1データなので、For~Nextでまわしまくる
With ThisSheet
For I = 2 To LastCnt
For J = I To I + 4
Select Case J - I
Case 0
ID = .Cells(J, 1).Value
StrName = Replace(.Cells(J, 3).Value, Name, "")
StrAddress = .Cells(J, 4).Value
Case 1
StrService = Replace(.Cells(J, 3).Value, Service, "")
StrPost = Replace(.Cells(J, 4).Value, Post, "")
Case 2
StrNumber = Replace(.Cells(J, 3).Value, Number, "")
StrTel = Replace(.Cells(J, 4).Value, TEL, "")
Case 3
StrFax = Replace(.Cells(J, 4).Value, FAX, "")
End Select
Next
’ここは1番最初にでーた入れるときに必要だった。。。
NumRow = .Cells(1, 5).End(xlDown).Row + 1
If NumRow = 65537 Then
NumRow = 2
End If
’拾ったデータを代入代入代入
.Cells(NumRow, 5).Value = ID
.Cells(NumRow, 6).Value = StrService
.Cells(NumRow, 7).Value = StrNumber
.Cells(NumRow, 8).Value = StrName
.Cells(NumRow, 9).Value = StrPost
.Cells(NumRow, 10).Value = StrAddress
.Cells(NumRow, 11).Value = StrTel
.Cells(NumRow, 12).Value = StrFax
’Iを6行すすめて次のデータへJump!
I = J - 1
Next
End With
End Sub
かんたんプログラミング Excel2003 VBA 基礎編/大村 あつし

¥2,499
Amazon.co.jp
補填を全部してくれないし・・・ヾ(▼ヘ▼;)
でも、やっている最中なんですけど 何か?(・ε・)
さて、あるリストをもらったんだけど、それをワンクリックで一定の項目で並べ替えてくれって言われちゃったよ。。。(む~り~。(´д`lll) )
でもやりました。
リストはどこまであるのっていうCountをしたかったので、
こんなに便利な書き方を見つけました。
教えてくれたサイト(ありがとう)
http://www.happy2-island.com/
ActiveSheet.Cells(Row,Column).End(xlDown).Row
一発ででてきました。。。( ̄□ ̄;)!!すげっ
世の中なんでもぐぐったら見つかる!!いい世の中だ・・・
作ったVBEものせとこ
Private Sub test()
Dim ThisSheet As Worksheet
Dim I As Integer, J As Integer
Dim LastCnt As Long
Dim RowCnt As Long
Dim NumRow As Long
’余分な文字があるので、Replaceしちゃうぞ
Const Name As String = "名称:"
Const Service As String = "サービス:"
Const Number As String = "番号:"
Const Post As String = "郵便番号:"
Const TEL As String = "電話:"
Const FAX As String = "ファクス:"
Dim ID As Integer
Dim StrName As String
Dim StrService As String
Dim StrNumber As String
Dim StrPost As String
Dim StrAddress As String
Dim StrTel As String
Dim StrFax As String
Set ThisSheet = ActiveSheet
’ここ!で使いました。
LastCnt = ThisSheet.Cells(1, 4).End(xlDown).Row
’6行ずつ2列で1データなので、For~Nextでまわしまくる
With ThisSheet
For I = 2 To LastCnt
For J = I To I + 4
Select Case J - I
Case 0
ID = .Cells(J, 1).Value
StrName = Replace(.Cells(J, 3).Value, Name, "")
StrAddress = .Cells(J, 4).Value
Case 1
StrService = Replace(.Cells(J, 3).Value, Service, "")
StrPost = Replace(.Cells(J, 4).Value, Post, "")
Case 2
StrNumber = Replace(.Cells(J, 3).Value, Number, "")
StrTel = Replace(.Cells(J, 4).Value, TEL, "")
Case 3
StrFax = Replace(.Cells(J, 4).Value, FAX, "")
End Select
Next
’ここは1番最初にでーた入れるときに必要だった。。。
NumRow = .Cells(1, 5).End(xlDown).Row + 1
If NumRow = 65537 Then
NumRow = 2
End If
’拾ったデータを代入代入代入
.Cells(NumRow, 5).Value = ID
.Cells(NumRow, 6).Value = StrService
.Cells(NumRow, 7).Value = StrNumber
.Cells(NumRow, 8).Value = StrName
.Cells(NumRow, 9).Value = StrPost
.Cells(NumRow, 10).Value = StrAddress
.Cells(NumRow, 11).Value = StrTel
.Cells(NumRow, 12).Value = StrFax
’Iを6行すすめて次のデータへJump!
I = J - 1
Next
End With
End Sub
かんたんプログラミング Excel2003 VBA 基礎編/大村 あつし

¥2,499
Amazon.co.jp
ListView同士のDrag&Drop
ListViewをフォームに2つ配置したのはいいけど、Drag&Dropがなかなかうまくいかん。
DragしたときのオブジェクトをEffectでわたせばいいんだよな~~~(°Д°;≡°Д°;)
しかし、書いてみるとみるみるいける!!・・・そしてTest成功!ヾ(@^▽^@)ノ
初めてのサンプル
Private Sub FileList_ItemDrag(ByVal sender As Object, _
ByVal e As System.Windows.Forms.ItemDragEventArgs) _
Handles FileList.ItemDrag
'ドラッグするときマウスのどっちのクリックかみてやる
If e.Button = MouseButtons.Left Then
Dim _listView As ListView
_listView = CType(sender, ListView)
FileList.DoDragDrop(e.Item, _
DragDropEffects.Move Or DragDropEffects.Copy)
End If
End Sub
Private Sub UserList_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles UserList.DragEnter
' ドロップされたデータが何か調べる
If e.Data.GetDataPresent(GetType(ListViewItem)) Then
e.Effect = DragDropEffects.Copy Or DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub UserList_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles UserList.DragDrop
Try
' ドロップされたやつが何か調べる
If e.Data.GetDataPresent(GetType(ListViewItem)) Then
Dim mitem As ListViewItem = _
DirectCast(e.Data.GetData(GetType(ListViewItem)), ListViewItem)
' 処理をかいてるけど、内情なので、ひ・み・つ
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "error")
End Try
End Sub
そして完成・・・・ハっ!!Σ(・ω・ノ)ノ!
複数選択(マルチはどうやんだ?)
明日にするっぺ。。。
今日のお助け
Visual Basic 2008 逆引きレシピ[Windows アプリケーション編] (PROGRAMMER’S RECiPE)/中垣 健志

¥2,520
Amazon.co.jp

DragしたときのオブジェクトをEffectでわたせばいいんだよな~~~(°Д°;≡°Д°;)
しかし、書いてみるとみるみるいける!!・・・そしてTest成功!ヾ(@^▽^@)ノ
初めてのサンプル
Private Sub FileList_ItemDrag(ByVal sender As Object, _
ByVal e As System.Windows.Forms.ItemDragEventArgs) _
Handles FileList.ItemDrag
'ドラッグするときマウスのどっちのクリックかみてやる
If e.Button = MouseButtons.Left Then
Dim _listView As ListView
_listView = CType(sender, ListView)
FileList.DoDragDrop(e.Item, _
DragDropEffects.Move Or DragDropEffects.Copy)
End If
End Sub
Private Sub UserList_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles UserList.DragEnter
' ドロップされたデータが何か調べる
If e.Data.GetDataPresent(GetType(ListViewItem)) Then
e.Effect = DragDropEffects.Copy Or DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub UserList_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles UserList.DragDrop
Try
' ドロップされたやつが何か調べる
If e.Data.GetDataPresent(GetType(ListViewItem)) Then
Dim mitem As ListViewItem = _
DirectCast(e.Data.GetData(GetType(ListViewItem)), ListViewItem)
' 処理をかいてるけど、内情なので、ひ・み・つ
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "error")
End Try
End Sub
そして完成・・・・ハっ!!Σ(・ω・ノ)ノ!
複数選択(マルチはどうやんだ?)
明日にするっぺ。。。
今日のお助け
Visual Basic 2008 逆引きレシピ[Windows アプリケーション編] (PROGRAMMER’S RECiPE)/中垣 健志

¥2,520
Amazon.co.jp