A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Opening file when file name is always different



 
 
Thread Tools Display Modes
  #11  
Old August 8th, 2004, 01:24 PM
Dave Peterson
external usenet poster
 
Posts: n/a
Default Opening file when file name is always different

First, I'd bet that my sample code blew up real good because I never set these
variables:

Dim NextWks As Worksheet
Dim PrevWks As Worksheet

You need something like:

set Newwks= worksheets("sheet1")
set prevwks = worksheets("sheet2")

And I had a couple of typos in the version that worked(?) from the top down:

if delrng is nothing then
set myrng = mycell
else
set myrng = union(mycell,delrng)
end if

Should read as:

if delrng is nothing then
set delrng = mycell
else
set delrng = union(mycell,delrng)
end if

But I don't think you can use matching up by row numbers to find the records to
delete--especially since the number of entries changes (but I could be wrong).
I'd look for the values in column B and compare them, then if they match, slide
of to column D and compare them again:

If that's true:

Option Explicit
Sub testme03()

Dim NextWks As Worksheet
Dim PrevWks As Worksheet
Dim res As Variant
Dim nextColB As Range
Dim prevColB As Range
Dim myCell As Range
Dim delRng As Range

'make these what you want
Set NextWks = Worksheets("sheet1")
Set PrevWks = Worksheets("sheet2")

With PrevWks
Set prevColB = .Range("b1", .Cells(.Rows.Count, "B").End(xlUp))
End With

With NextWks
Set nextColB = .Range("b:b") 'whole column
End With

For Each myCell In prevColB.Cells
res = Application.Match(myCell.Value, nextColB, 0)
If IsError(res) Then
'not found, do nothing
Else
If nextColB(res).Offset(0, 2).Value _
= myCell.Offset(0, 2).Value Then
'we have a double match
If delRng Is Nothing Then
Set delRng = myCell
Else
Set delRng = Union(myCell, delRng)
End If
End If
End If
Next myCell

If delRng Is Nothing Then
MsgBox "nothing to delete"
Else
delRng.EntireRow.Delete
End If

End Sub



"Lee Jeffery " wrote:

Dave P,

I'm doing something very, very wrong with your code.
Each one of your suggestions gives me a run-time error 91: Object
variable or With block variable not set on the For Each line. I've
tried to use the set command but still no success. Which variable am I
missing and how should this be set, please?

Many thanks. All help greatly appreciated.

Lee

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #12  
Old August 8th, 2004, 02:17 PM
Lee Jeffery
external usenet poster
 
Posts: n/a
Default Opening file when file name is always different

Thanks, Dave.

Although I'm close to babbling now, I'd finally worked out the Set
command but the results were leaving more info than I want. For testing
purposes, I have created 2 workbooks which are almost identical but I
have made manual adjustments to ten entries and coloured these so they
should be the only ones left in a successful exception report. These
entries are appearing but so is a large amount of info that should be
deleted.
I'll try your latest suggestion and see if I can be successful with
this.
Many thanks for your incredible patience with this.

Lee Jeffery


---
Message posted from http://www.ExcelForum.com/

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
You do not have exclusive access... ERROR Robin General Discussion 1 July 6th, 2004 01:18 AM
Application must be installed to run Error Keith Setup, Installing & Configuration 1 June 29th, 2004 03:02 AM
Need help on opening file through input once more ! Just4fun Worksheet Functions 2 June 26th, 2004 02:44 PM
Getting source lists w/o opening target file Arifi Koseoglu Links and Linking 5 May 25th, 2004 05:55 PM
problem opening .csv file Karen Setting up and Configuration 0 September 19th, 2003 02:23 AM


All times are GMT +1. The time now is 12:58 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.