maybe a compatibility issue

kevin lazell

Well-known Member
Joined
Jun 2, 2004
Messages
513
hi guys i have written this piece of code for my daughter which work ok on my machine excel2019
but will not run on hers runtime error 1004 is what she gets could this be a compatibility issue and is there a work around

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim X, Y, Z As Variant
Dim i As String
Range("d17") = "word"
i = "19th jul 2021"
Z = Range("D" & Rows.Count).End(xlUp).Row
Z = Z + 1
X = 2: Y = 2
again:
Do
If Range("D" & X) <> Sheets(i).Range("D" & Y) Then Y = Y + 1: GoTo again: 'this line gives the error
If Range("D" & X) = Sheets(i).Range("D" & Y) Then Range("O" & X).Copy
With Sheets(i).Range("O" & Y).PasteSpecial: X = X + 1: Y = 2
Application.CutCopyMode = False
End With
If X = Z Then Exit Sub
Loop

End Sub
thank you for any help she is running 365 by the way
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try
VBA Code:
If Range("D" & X) <> Sheets(i).Range("D" & Y) Then
   Y = Y + 1
   GoTo again
End If
 
Upvote 0
Solution
Are you sure you want to use this code on every selection change? Its also prone to an infinite loop should Range("D" & X) never be equal to Sheets(i).Range("D" & Y).
 
Upvote 0
hi fluff
sorry for the delay in replying my daughter has only just got back to me
your amendment to the code works just fine thank you very much for your time
could you please give an explanation as to why those couple of lines needed changing
 
Upvote 0
No idea why it should make a difference as the code works for me, however it's an unusual way of writing it.
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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