Range class method could not be selected using VBA

This is the code I'm working with now and I am getting this problem. I am new to Excel and I cannot understand what happened.

Private Sub cmdRecord_Click()
Sheets("BxWsn Simulation").Range("Result").Select //This is the line with the problem, as excel told me.
    Selection.Copy
    Sheets("Reslt Record").Select
    Sheets("Reslt Record").Range("A5000").End(xlUp).Offset(1).Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("CuCon Simulator").Select
    Application.CutCopyMode = False
    Range("Improvement").Select
End Sub

Error is a method for selecting Range class with error via VBA, error 1004. Any ideas?

Thank.

Edit:

So, I just changed the code to

Sheets("BxWsn Simulation").Select
Range("Result").Select

I suppose this is what you mean by making it active? However, I still get the Range method of the Desktop object, error 1004

+12
source share
4 answers

I believe that you have the same problem here.
The sheet must be active before you can select a range on it.

, :

Sheets("BxWsn Simulation").Select
Sheets("BxWsn Simulation").Range("Result").Select

With Sheets("BxWsn Simulation")
  .Select
  .Range("Result").Select
End WIth

.

+22

- " ". , 99% .

Select something
Do something to the selection
Select something else
Do something to the selection

, .

, 'Range' '_Worksheet' , 1004, , , "". (, ) , , . Range Range. Range, Excel .

. , ActiveSheet , Excel ActiveSheet.Range( "" ). ( ). , , . , , , .

Excel , , "_Object" ( "_Worksheet" ), - . , , , . , , .

.

Private Sub cmdRecord_Click()

    Dim shSource As Worksheet
    Dim shDest As Worksheet
    Dim rNext As Range

    'Me refers to the sheet whose class module you're in
    'Me.Parent refers to the workbook
    Set shSource = Me.Parent.Worksheets("BxWsn Simulation")
    Set shDest = Me.Parent.Worksheets("Reslt Record")

    Set rNext = shDest.Cells(shDest.Rows.Count, 1).End(xlUp).Offset(1, 0)

    shSource.Range("Result").Copy
    rNext.PasteSpecial xlPasteFormulasAndNumberFormats

    Application.CutCopyMode = False

End Sub

, , , - . Me.Parent ActiveWorkbook. , - .

, , , , , , , , ScreenUpdating. , .

+14

.

RowCounter = Sheets(3).UsedRange.Rows.Count + 1

Sheets(1).Rows(rowNum).EntireRow.Copy
Sheets(3).Activate
Sheets(3).Cells(RowCounter, 1).Select
Sheets(3).Paste
Sheets(1).Activate
+2

, . sheet(x).range Activesheet.range("range").select

-1
source

All Articles