Elseif statements - 'Application-Defined or Object-defined error' help

Sppinner

New Member
Joined
May 6, 2013
Messages
20
Hello,

Currently I am trying to use Elseif statments to copy and paste information into a target cell from another cell on the same worksheet based on the value of the target cell.

When I try to run my code, I recieve the following error message:
'Run-time error 1004: Application-based or Object-based error"

Can anybody advise me on how to change my coding to fix this issue?
Here is the coding I have created:

Sub helpMe()

Dim i As Integer
Dim j As Integer

For i = 6 To 30

For j = 4 To 18

If Cells(i, j).Value = 5 Then
Range(A43).Select.Copy
Cells(i, j).Select.Paste

ElseIf Cells(i, j).Value = 4 Then
Range(A42).Select.Copy
Cells(i, j).Select.Paste

ElseIf Cells(i, j).Value = 3 Then
Range(A41).Select.Copy
Cells(i, j).Select.Paste

ElseIf Cells(i, j).Value = 2 Then
Range(A40).Select.Copy
Cells(i, j).Select.Paste

ElseIf Cells(i, j).Value = 1 Then
Range(A39).Select.Copy
Cells(i, j).Select.Paste

Else: Cells(i, j).Value = ""

End If

Next j

Next i

End Sub

Is someone able to assist me in fixing this error or tell me of a better way to do this?

Thank you,

-Sppinner
 

bbott

Well-known Member
Joined
Feb 5, 2010
Messages
2,350
Range(A43).Select.Copy
These lines need to be written as:
Code:
Range("A43").Copy
When naming a cell in the Range object, it needs to be in quotes. You also don't need the .Select
 
Last edited:

Sppinner

New Member
Joined
May 6, 2013
Messages
20
Thank you for your help! It has gotten me past the run-time error 1004

Now however, I am getting "Runtime error 438: object doesn't support this property of method"

Thoughts on why this is?
 

Sppinner

New Member
Joined
May 6, 2013
Messages
20
It's not highlighting any lines... any way for me to check manually?
 

Forum statistics

Threads
1,081,545
Messages
5,359,450
Members
400,528
Latest member
Ratish52

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top