I have a bit of visual basic code in an excel spreadsheet that I need some help with. I am attempting to search a file called TO Cancellations2. xls for counterparty names and for each counterparty name that it finds that matches the list of counterparties on the "counterparties " sheet of a file called Time Option Template WIP.xls I want the whole line copied and pasted into a new excel worksheet that should have the counterparty name and then FXTOX.xls after it.
The TO Cancellation2.x ls file looks like this
Counterparty
Oy AB 109385 H2 07
Oy AB 109389 H1 08
Oy AB 109390 H2 08
Oy AB 109387 H2 07
Oy AB 109388 H1 08
AB (Sweden) 109391 H2 08
The code below works ok but if the TO Cancellations2. xls file has the same counterparty more than once (as in this case with 5 different records against Oy AB) then instead of saving all 5 records into one file it overwrites the file each time with each of these 5 instances - only keeping the last record. Can anyone suggest any ideas on how to alter this code so that if there is more than one row countaining the same counterparty name it saves all of the rows to the same file and doesn't keep overwriting like it is currently doing?
Sheets("Counter parties").Selec t
' Initialise Counter
Countz = 0
For Each c In Range("A1:A100" )
If c.Value = "" Then
Exit For
Else
Countz = Countz + 1
End If
Next c
Sheets("Data2") .Select (NB data2 is a sheet in the Time Option Template WIP.xls file)
Range("A1").Sel ect
For Counter = 1 To Countz
Set Matching = Worksheets("Cou nterparties").C ells(Counter, 1)
Set Matching2 = Worksheets("Cou nterparties").C ells(Counter + 1, 1)
Set Matching3 = Worksheets("Cou nterparties").C ells(Counter + 2, 1)
Set Matching4 = Worksheets("Cou nterparties").C ells(Counter + 3, 1)
Set Matching5 = Worksheets("Cou nterparties").C ells(Counter + 4, 1)
Set Matching6 = Worksheets("Cou nterparties").C ells(Counter + 5, 1)
Set Matching7 = Worksheets("Cou nterparties").C ells(Counter + 6, 1)
For Each c In Range("A1:A5001 ")
If c.Value = Matching.Value Then
If c.Offset(0, 0).Value = Matching2.Value Or c.Offset(0, 0).Value = Matching3.Value Or c.Offset(0, 0).Value = Matching4.Value Or c.Offset(0, 0).Value = Matching5.Value Or c.Offset(0, 0).Value = Matching6.Value Or c.Offset(0, 0).Value = Matching7.Value Then
Else
c.EntireRow.Sel ect
Selection.Copy
Workbooks.Add
ActiveSheet.Pas te
Cells(2, 1).Select
stdocname = "Q:\Dealing Room\Dealing room administration\ Admin Things\Batch Report Masters\Outputs \" & Matching.Value & " FXTOX.xls"
ActiveWorkbook. SaveAs Filename:=stdoc name _
, FileFormat:=xlN ormal, Password:="", WriteResPasswor d:="", _
ReadOnlyRecomme nded:=False, CreateBackup:=F alse
Windows("Time Option Template WIP.xls").Activ ate
stdocname = Matching.Value & " FXTOX.xls"
Counti = 2
Do Until c.Offset(Counti , 0).Value = Matching2 Or c.Offset(Counti , 0).Value = Matching3 Or c.Offset(Counti , 0).Value = Matching4 Or c.Offset(Counti , 0).Value = Matching5 Or c.Offset(Counti , 0).Value = Matching6 Or c.Offset(Counti , 0).Value = Matching7 Or c.Offset(Counti , 0).Value = "Contact RG"
c.Offset(Counti , 0).EntireRow.Se lect
Selection.Copy
Windows(stdocna me).Activate
Cells(Counti + 1, 1).Select
ActiveSheet.Pas te
Windows("Time Option Template WIP.xls").Activ ate
Counti = Counti + 1
Loop
0 1753 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Fred |
last post by:
Hi.
How do I import while mapping an excel table to an access table please???
I've searched around and all I can find is a software product or code that
does the same thing as the access wizard.....
If I have to write vb code, where is a sample???
Or do I import the excel in to a new spreadsheet and then
write some kind of querey to move the data from that table
|
by: D |
last post by:
I've created a report with many subreports of aggregate data. I want my
client to be able to export this data to Excel to make her charts, etc. Only
one problem: one of the fields is a "SchoolYear" TEXT field that contains
data such as 2000/01, 2001/02, etc. If I export a Query with this kind of
data to Excel, it gives me the text value of this field; however, when I
export a Report bound to this TEXT field, Excel gives me the values 36526,...
|
by: Peter Frost |
last post by:
Please help
I don't know if this is possible but what I would really like to do is
to use On Error Goto to capture the code that is being executed when
an error occurs.
Any help would be much appreciated.
Thanks in advance
|
by: David Reynolds |
last post by:
Hi Everybody,
I have a vb.net webform where I create the Excel
application/workbook/worksheet. On Windows 2000 server for some reason, I
keep getting an error("Bad variable type") when trying to first set the value
to a cell. I don't have the problem on 2003 server or XP, and I'm wondering
if anyone knows of a get around on 2000?
Try
EApp = CreateObject("Excel.Application")
|
by: Coleen |
last post by:
Hi All :-)
I'm using .Net Framework 1.1, VB and need to be able to download the data
from a datagrid into an Excel 2000 spreadsheet for our accounting users.
Can anyone please point me to a good link on how to do this or give me some
pointers? TIA,
Coleen
| |
by: rssd |
last post by:
can somebody help me. I'm trying to read some excel files but i'm always getting this error
No type library matching "Microsoft Excel" found at D:\Genes_datasets\exp.pl line 4
Win32::OLE(0.16): GetOleTypeLibObject() Not a Win32::OLE::TypeLib object at C:/Perl/site/lib/Win32/OLE/Const.pm line 45.
Died at D:\Genes_datasets\exp.pl line 6.
i don't ve microsoft excel but open office installed, i think that could be a problem. But these...
|
by: =?Utf-8?B?THluZXJz?= |
last post by:
Hello All,
We have a VB.NET application writen using VS 2003. This application apens an
excel file from a vendor, reads the data and performs whatever functions it
needs. We recently upgraded our sytems to Excel 2003 from Excel 2000. Our
application started erroring out because it was having a problem with opening
the Excel file.
From troubleshooting, the exact problem is in Excel 2003, it does not like
the sheet name (even though the...
|
by: grego9 |
last post by:
--------------------------------------------------------------------------------
I have a bit of visual basic code in an excel spreadsheet that I need some help with. I am attempting to search a file called "TO Cancellations2.xls" for names and for each name that it finds that matches the list of names on the "counterparties" sheet of a file called Time Option Template WIP.xls I want the whole line copied and pasted into a new excel...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |