View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Run-Time error 1004????

Hi Ken,

It is not clear (to me!) where you say your error is occurring.

Also, why do you set the Rng1 and Rng2 variables to ranges on Worksheets(2)
and then immediately reassign these variables to ranges on the Replace Info
sheet.

Perhaps you could post the entire relevant code portion?

---
Regards,
Norman



"Ken Loomis" wrote in message
...
This piece of code worked just fine:

Dim Rng1 As Range, Rng2 As Range
Dim MyRng As Range

With Worksheets(2)
Set Rng1 = .Range("A5") '<<=== Given Start cell
Set Rng2 = .Cells(Rows.count, "D").End(xlUp)
End With

With Sheets("Replace Info")
Set Rng1 = .Range("A5") '<<=== Given Start cell
Set Rng2 = .Cells(Rows.count, "D").End(xlUp)
End With

Set MyRng = Range(Rng1, Rng2)
ReplaceArray = MyRng

searches = UBound(ReplaceArray, 1)

For srchCnt = 1 To searches
findIt = ReplaceArray(srchCnt, 1)
ReplaceWith = ReplaceArray(srchCnt, 2)
InColumn = ReplaceArray(srchCnt, 3)
Set rFound = Columns(InColumn).Find(findIt)

- code snipped here <-


Until I added and deleted some worksheets. Now I am getting a run-time
error 1004 at the last line of that code and Rng1 = the value from cell
A5.

So I tried this:

With Worksheets("Replace Info")
Set Rng1 = .Range("A5") '<<=== Given Start cell
Set Rng2 = .Cells(Rows.count, "D").End(xlUp)
End With



And this,

With Sheets("Replace Info")
Set Rng1 = .Range("A5") '<<=== Given Start cell
Set Rng2 = .Cells(Rows.count, "D").End(xlUp)
End With


But neither of those work.

Can someone tell me how to fix this? And, if possible tell me what I am
not getting about this? Maybe suggest some online reading. I have already
ordered 2 books that were earlier suggested, but I need to get this
project done before they get here.

Thanks for any help and insights.

Ken Loomis