maybe a compatibility issue

kevin lazell

Well-known Member
Joined
Jun 2, 2004
Messages
506
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
64,131
Office Version
  1. 365
Platform
  1. Windows
Try
VBA Code:
If Range("D" & X) <> Sheets(i).Range("D" & Y) Then
   Y = Y + 1
   GoTo again
End If
 
Solution

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,644
Office Version
  1. 365
Platform
  1. Windows
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).
 

kevin lazell

Well-known Member
Joined
Jun 2, 2004
Messages
506
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
64,131
Office Version
  1. 365
Platform
  1. Windows
No idea why it should make a difference as the code works for me, however it's an unusual way of writing it.
 

Forum statistics

Threads
1,144,680
Messages
5,725,751
Members
422,636
Latest member
GatorsBucs

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
Top