• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Workbook Reference

KishorKK

Member
Hi,

Using workbook reference i would like to enter values in different work sheet. Here i wrote the code but it's not executing, i'm getting error pls help
 

Attachments

  • WhatsApp Image 2016-11-26 at 7.52.15 PM.jpeg
    WhatsApp Image 2016-11-26 at 7.52.15 PM.jpeg
    110.7 KB · Views: 24
  • WhatsApp Image 2016-11-26 at 7.52.22 PM.jpeg
    WhatsApp Image 2016-11-26 at 7.52.22 PM.jpeg
    13.6 KB · Views: 18
Hi,

You ref. "Sheet(1)" it should be "Sheets(1).
I believe you are setting the Ref workbook to the wrong workbook it should be the workbook you have the code in.
Here's my sample code
Code:
Sub test()
ActiveWorkbook.Sheets(1).Range("A1:D10").Value = "Test"
End Sub
 
Hello Kishore.

May be this.

Sub Kishore()

Dim Actwrbk As Workbook
Set Actwrbk = ActiveWorkbook
Actwrbk.Activate
Actwrbk.Worksheets("Sheet1").Range("A1:D10").Value = "Test"

End Sub
 
Kishore,
Any time that you are referencing a workbook you need to make sure the code runs against the desired workbook. If it needs to look at a workbook that is not open you must open that workbook. Ie:

Code:
''' the workbook you need to work on must be in the same file/path as the     ''workbook that the code is in'''
Workbooks.Open Filename:=ThisWorkbook.Path & "\Schedule.xls"
ActiveWorkbook.Sheets(1).Range("A1:D10").Value = "Test"
 
Back
Top