Your problem is that you are referencing an incorrect point, it appears that your 'xlbook' is not correctly assigned, then the Sheet1 is not assigned, then the Cell range is not assigned, thus the '=D2/256' goes into the (previously) 'active' cell instead of U2.Originally Posted by daboyroy
(by 'assigned', I mean 'activated/selected' etc)
I hope this helps you track the error, I may find more details but the 'Select' / 'Activate' and when/why to do those is a little ahead of my current learning.
Added:
WithI can achieve what you appear to be doing, but after the msgbox I do not understand what you are trying to do.![]()
Sub ttyu() Dim xlBook As Workbook Dim xlSheet As Worksheet Set xlBook = Workbooks.Add Set xlSheet = Worksheets("Sheet1") xlSheet.Activate Dim i Dim CurrentCell Dim OldComp Dim NewComp With xlSheet .Range("U1").Select ActiveCell.Formula = "Latency" Application.CutCopyMode = False .Range("U2:U50000").Formula = "=D2/256" xlSheet.Range("V1").Select ActiveCell.FormulaR1C1 = "Type" .Range("V2:V50000").Formula = "target" .Columns("T:T").Copy ' note, there is nothing in T .Range("W:W").Select ActiveSheet.Paste Application.CutCopyMode = False MsgBox "to here" OldComp = 0 For i = 0 To 50000 CurrentCell = "W" & i + 2 .Range("CurrentCell").Activate 'HERE AN ERROR OCCURS: METHOD RANGE OF OBJECT _WORKSHEET FAILED. IF I LOSE THE 'xlSheet' PART, I GET: METHOD RANGE OF OBJECT _GLOBAL FAILED. NewComp = ActiveCell.Value If NewComp = OldComp Then xlSheet.Rows(i + 2).Delete End If OldComp = xlSheet.Range("CurrentCell").Value Next 'i End With End Sub
What was 'target' put into column V ?
hth
---
---
Bookmarks