LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Run-Time error 1004????

Hi Ken,

Until I added and deleted some worksheets ...


In your code line:

Set rFound = Columns(InColumn).Find(findIt)


Columns is not qualified and, therefore, refes to the active sheet. An added
worksheet becomes the active sheet and Columns may reference the wrong
sheet.

It is much safer to explicitly qualify your ranges:

Set RFound = Sheets("Replace Info").Columns(InColumn).Find(findit)

This way, the correct range will be referenced even if you add or delete
sheets.


---
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







 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time error 1004... JSnow Excel Discussion (Misc queries) 3 December 19th 08 08:48 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
Run-time error 1004 aarslev Excel Programming 1 December 22nd 03 11:25 PM
Run Time Error 1004 Lars Kofod Excel Programming 1 December 5th 03 02:56 AM
Run time error 1004 Eric[_14_] Excel Programming 0 December 3rd 03 12:41 AM


All times are GMT +1. The time now is 08:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"