View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Jackson Jim Jackson is offline
external usenet poster
 
Posts: 324
Default I need a VB script for Excel

There probably are faster ways to do this byt the following should do what
you want.

Sub Macro2()
'
Dim retval
Dim wk1, wk2
Set wk1 = Workbooks("Book1.xls")
Set wk2 = Workbooks("Book12.xls")

wk1.Activate
Sheets("Sheet1").Activate
Range("A1").Activate
retval = ActiveCell

wk2.Activate
Sheets("Sheet1").Activate
Range("A1").Activate

For Each cell In Sheets

Do
If ActiveCell = "" Then
wk1.Activate
ActiveCell.Delete shift:=xlUp

If ActiveCell = "" Then
Exit Sub
Else
retval = ActiveCell
wk2.Activate
Range("A1").Activate
End If

ElseIf ActiveCell < retval Then
ActiveCell.Offset(1, 0).Activate
ElseIf ActiveCell = retval Then
wk1.Activate
ActiveCell.Offset(0, 1) = "OK" ' This line was used as a check
ActiveCell.Offset(1, 0).Activate
retval = ActiveCell
wk2.Activate
Range("A1").Activate

End If
Loop
Next

End Sub
--
Best wishes,

Jim


"pretextat" wrote:


Well I think I need one..

It's when you are in trouble that you discovers forum like here. I hope
someone can help and that I will also be able to help people in the
future. BTW sorry for my english its not my mother tongue

My problem:

I have two files:

file1.xls with A1 column numbered as below:
1
2
3
4
5
6
7
8
...

file2.xls with A1 column numbered as below:
1
2
3
7
8
15
28
...

Now what I need is a script that compares the two files and deletes the
numbers from file1.xls that are not present in file2.xls (from the
example above: 4,5,6,9,10,11,12,13,14,16...). So in the end file1.xls
and file2.xls would have the same number of row. Please take note that
file1.xls has a total of 8 columns and file2.xls 12 columns. File1.xls
have around 2000 rows and file2.xls around 1200 rows.

Anyone can help, please? Any other solution is welcome.

I know how to use a VB script in Excel with one single file. Is it
different when the script involves two files. Please give me some
explanations just in case I have problems using it.

Thanks in advance


--
pretextat
------------------------------------------------------------------------
pretextat's Profile: http://www.excelforum.com/member.php...o&userid=36512
View this thread: http://www.excelforum.com/showthread...hreadid=562698