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

下記のようなコードを組んだのですが、
エラーが発生しうまく進めません。
どのように修正すればよいか
ご教示いただけると助かります。

On Error Resume Nextを使うと
別のところに貼り付けられました。。。


With Sheets("移行前").Select

Selection.End(xlUp).Select
Range("AV1:AW1").Select
ActiveCell.Offset(1, 0).Activate

Range("AV3:AW" & Cells(3).CurrentRegion.Rows.Count).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
End With

With Sheets("データシート").Select
Set FoundCell = Range("2:2").Find(What:="仮金額")
Set N = Cells(.Rows.Count, FoundCell.Column).End(xlUp).Row + 1  ←エラー:オブジェクトが必要です。
Cells(N, FoundCell.Column).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With

A 回答 (5件)

Sub goo02()


Dim N As Long
Dim FoundCell As Range
Sheets("移行前").Select
Range("AV3:AW" & Cells(3, "AW").End(xlDown).Row).Copy
Sheets("データシート").Select
Set FoundCell = Range("2:2").Find(What:="仮金額", LookIn:=xlValues, LookAt:=xlWhole)
N = Cells(Rows.Count, FoundCell.Column).End(xlUp).Row + 1
Cells(N, FoundCell.Column).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
End Sub
    • good
    • 0

>Set N = Cells(.Rows.Count, FoundCell.Column).End(xlUp).Row + 1


【.Rows.Count】の前の、withは、【With Sheets("データシート")】になっていて、【FoundCell 】ではないので、そこがエラーの原因でしょう。
変数「N」は長整数型(または整数型)ですよね?

>Set N = Cells(.Rows.Count, FoundCell.Column).End(xlUp).Row + 1
⇒ N = Cells(FoundCell .Rows.Count, FoundCell.Column).End(xlUp).Row + 1

>Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
【 Paste】するものがないです。コピーしておく必要があると思います。
⇒ 
Cells(N, FoundCell.Column).Select
Selection.copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

ただ、このコードは何をしようとしているのかがわかりません。
また、.Select をこのように使う理由がわからないです。
Setの使い方も、理由がわかりません。
    • good
    • 0

こんにちは!



変数「N」を何の型で宣言しているのか不明ですが・・・
コードを拝見する限り、変数「N」は長整数型(または整数型)ですよね?

となると
>Set N = Cells(.Rows.Count, FoundCell.Column).End(xlUp).Row + 1

>N = Cells(.Rows.Count, FoundCell.Column).End(xlUp).Row + 1
で良いと思います。m(_ _)m
    • good
    • 0

エラーが出た時は「FoundCell.Column」には何が代入されていますか?

    • good
    • 0

rows.countの前の.を消したらダメなのですか?

    • good
    • 0

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