2

I am trying to set the value of a cell with one of the function parameters. The code is giving an error 91. The 6th line in the code is raising the error:

Thanks in advance.

Sub report_file(a, r_row)
Dim wb_dst As Workbook
Dim ws_dst As Worksheet
Set wb_dst = Workbooks.Open("F:\Projects\vba_excel\report.xlsx")
ws_dst = wb_dst.Sheets(1)
ws_dst.Cells(r_row, 2).Value =a
End Sub

The error line is:

ws_dst.Cells(r_row, 2).Value =a
7
  • 1
    6th line? remove Set in this line Set wb_dst.cell(r_row, 2).Value = a and give us a feedback what is going wrong now. Commented May 8, 2013 at 14:48
  • what's the value of 'a' and what's the value of 'r_row'? Also you have a typo in your if statement. It should be wb_dst.Cells and not wb_dst.cell. Actually I'm pretty sure you don't need that if statement at all..unless you're just doing it as a test. Commented May 8, 2013 at 14:48
  • @KazJaw : it shows the same error "91" Commented May 8, 2013 at 14:53
  • 1
    add Set instruction to this line ws_dst = wb_dst.Sheets(1) to create Set ws_dst = wb_dst.Sheets(1) Commented May 8, 2013 at 14:57
  • 6
    Your 5th line needs a Set. Commented May 8, 2013 at 14:58

1 Answer 1

2
Option Explicit

Sub report_file(a, r_row)
    Dim wb_dst As Workbook
    Dim ws_dst As Worksheet
    Set wb_dst = Workbooks.Open("F:\Projects\vba_excel\report.xlsx")
    Set ws_dst = wb_dst.Sheets(1)
    ws_dst.Cells(r_row, 2).Value = a
    If a = "savior" Then
        wb_dst.Cells(r_row, 2).Value = a
    End If
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.