アプリ版:「スタンプのみでお礼する」機能のリリースについて

マクロで検索、抽出して別ファイルに保存したいのですが、
以下のようなマクロを教えてもらったのですが
コピー先のセル位置を任意の位置に直したいのですが、
どうしてもわかりません
どの部分をどう直せばよいのでしょうか?

Option Explicit

Sub copyTodayData()
Dim dateToday As String
Dim tempDate As String
Dim lastrow1 As Long
Dim lastrow2 As Long
Dim i As Long
Dim fileA As String
Dim anotherBook As String
Dim anotherFilePath As String

fileA = ThisWorkbook.Name
anotherBook = "別のファイル.xls"
anotherFilePath = "C:\Documents and Settings\日本太郎\デスクトップ\どこかのフォルダ"


'問い合せダイアログの表示をOFFにします
Application.DisplayAlerts = False

'ファイルを開く
ChDir anotherFilePath
Workbooks.Open Filename:=anotherFilePath & "\" & anotherBook

'問い合せダイアログの表示をONに戻します
Application.DisplayAlerts = True

'ウインドウの切替
Windows(fileA).Activate

'今日の日付を取得
dateToday = Date

'データ最終行を取得
lastrow1 = Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To lastrow1
If Cells(i, 1) = dateToday Then
'Range(Cells(i, 1), Cells(i, 4)).Copy 'コピー
Windows(anotherBook).Activate 'ウインドウの切替
lastrow2 = Cells(Rows.Count, 1).End(xlUp).Row '別ブックの最終行
Cells(lastrow2 + 1, 1).Select
ActiveSheet.Paste
Windows(fileA).Activate 'ウインドウの切替
End If
Next i

MsgBox "実行しました"

End Sub


たぶん、lastrow2 = Cells(Rows.Count, 1).End(xlUp).Row '別ブックの最終行
Cells(lastrow2 + 1, 1).Select
ここらへんというのは、わかりますが、
どこをどう変えたらいいかわかりません

A 回答 (1件)

VBEを開いて


lastrow2 = Cells(Rows.Count, 1).End(xlUp).Row '別ブックの最終行
の行をクリックしてからF9キーを押してブレークポイントを作成する(行に色がつく)

マクロを実行すると上記の行で止まるので、上記の行のイコールの左辺lastrow2にカーソルを置くと
lastrow2の値が表示されます。

F8キー押下で
Cells(lastrow2 + 1, 1).Select
行に移ります。

もう一度F8キー押下でどのセルが選択されるか、確認できます。


ブレークポイントの解除は、再度F9キー押下。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!