2

I have this sub in Excel 2010 that’s supposed to do the following:

·         Take the value in (6, 4) in Sheet1(Form) and find this value in Sheet7’s (Dates) column 1

·         Find the row in which it finds this match

·         Find the value at Sheet7(row, 6)

·         Paste it into Sheet1(19, 5)

Sheet1 is titled Form, and Sheet7 is titled Dates.

This is the code that I’ve written. When I try to run it, it gives me a run-time error ‘1004: Application-defined or object-defined error’ at Sheets("Dates")... Any assistance would be greatly appreciated.    

 Option Explicit

Private Sub btnNext_Click()
        Dim ProjNo As String
        Dim ProjRow As Long
        Dim Found As Range   

    ProjNo = Worksheets("Form").Cells(6, 4).Value        

         Set Found = Sheets("Dates").Columns(1).Find(what:=ProjNo, LookIn:=xlValues, lookat:=xlWhole)

          If Found Is Nothing Then   
              MsgBox "Project not found."    
              EnterProj.Show    
         Else   
             ProjRow = Found.Row    
        End If        

          Sheets("Dates").Range(ProjRow, 6).Copy Destination:=Sheets("Form").Range(19, 5)    

End Sub
7
  • Sheets("Dates").Columns(1) no quotes on 1 Commented Jul 22, 2014 at 15:12
  • Now I get the error at Sheets("Dates")... Commented Jul 22, 2014 at 15:13
  • 'Sheets("Dates").Range(ProjRow, 6).Copy Destination:=Sheets("Form").Range(19, 5)' , remove the qoutes Commented Jul 22, 2014 at 15:20
  • It's still giving me the same error at the same spot. Commented Jul 22, 2014 at 15:23
  • I suggest you update the code with what you now have based on the corrections already suggested. Commented Jul 22, 2014 at 15:24

1 Answer 1

5

You are not using the Range Object Correctly,

For e.g.

.Range(2,6)<>Cells(2,6), Range parameters has to be A1-style reference or other styles

Replace

Sheets("Dates").Range(ProjRow, 6).Copy Destination:=Sheets("Form").Range(19, 5)

with

Sheets("Form").Cells(19, 5)=  Sheets("Dates").Cells(ProjRow, 6) 
Sign up to request clarification or add additional context in comments.

4 Comments

It didn't give me an error, but it also didn't paste the value from the one sheet to the other.
How is the second line performing the desired task? The first line (if you swapped Range for Cells) is trying to copy from projRow to row 19. You are assigning to projRow instead of row 19
Oops My bad I flipped the source and destination, I updated the answer
All he really needed to do to get the code working was flip Range for Cells in both instances on that line and then it works on my machine. Yours is better though since it sounds like all he wants in this case is the value.

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.