help needed on run time error 9 subscript out of range

Excelworld

New Member
Joined
Nov 10, 2011
Messages
33
Hi,

I'm getting the above error when running the VB code - basically I want the code to check which active workbook is open before it pastes the data in. Both workbooks are set up the same but with different names and the code runs from a separate workbook - I'm using excel 2010

Code:
Sub sheetup()
'
' Copies the details of the candidate onto the main management tracker
'
    Range("AC71:AJ71").Select
    Selection.Copy
  Windows("work1.xls").Activate
  ActiveWorkbook.Sheets("CANDIDATES").Activate
  On Error Resume Next
  Windows("work2.xls").Activate
  ActiveWorkbook.Sheets("CANDIDATES").Activate
    Range("C" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
    Dim LastRow As Long
    LastRow = Sheets("Candidates").Range("C" & Cells.Rows.Count).End(xlUp).Offset(1).Row
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("C" & Cells.Rows.Count).End(xlUp).Offset(1, 0).Select
End Sub

any ideas?
 
Try stepping into your code and proceeding through it line-by-line using the F8 key until you find where the error occurs.
If you resize your VB window down to about one-quarter the size of the screen, you will be able to see exactly what it is doing behind the scenes and should be able to see why the error is occurring.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top