473,379 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Search open files for string and then copy that row into a new workbook

Hello,
I am trying to develop a vb program for Excel which will search through open workbooks for a text string (let's say that string is "error" for example) in a cell. Once this program finds this string, I need it to copy that cell and adjacent cells into a different workbook (this will be used to summarize the errors). As it copies this information, it would be nice if it stepped down the page as it pasted (so all the error cells wouldn't be pasted on top of one another). I am pretty new to vb and have been searching the web for a similar post but have not found it. I really appreciate any help you can give!

Thanks,
nick
Mar 12 '08 #1
2 1382
jeffstl
432 Expert 256MB
Hello,
I am trying to develop a vb program for Excel which will search through open workbooks for a text string (let's say that string is "error" for example) in a cell. Once this program finds this string, I need it to copy that cell and adjacent cells into a different workbook (this will be used to summarize the errors). As it copies this information, it would be nice if it stepped down the page as it pasted (so all the error cells wouldn't be pasted on top of one another). I am pretty new to vb and have been searching the web for a similar post but have not found it. I really appreciate any help you can give!

Thanks,
nick
Are you creating a seperate .exe that will perform this job?...or are you developing the VB Code in Excel (VBA) ?

Pretty tall order....I don't think anyone will post the work for you so you will probably be better off getting started and getting down to the specific problems you run into.

I do have a huge VBA app written in excel that reads various cells and generates graphs, etc, but none of this is pretty and its all completely dependant on individual format\design of the actual spreadsheet your working with.
Try this I guess for now and see how you do:
http://www.excel-vba.com/excel-vba-contents.htm
Mar 12 '08 #2
Ok here's what I have so far. It's an amalgamation of many snippets I've found online so far:

ub test()
Dim wbk As Workbook
Dim sht As Worksheet

For Each wbk In Workbooks
For I = 1 To Worksheets.Count
Dim LSearchRow As Integer
Dim LCopyToRow As Integer

On Error GoTo Err_Execute

'Start search in row 4
LSearchRow = 4

'Start copying data to row 2 in Sheet2 (row counter variable)
LCopyToRow = 2

While Len(Range("A" & CStr(LSearchRow)).Value) > 0

'If value in column E = "Mail Box", copy entire row to Sheet2
If Range("B" & CStr(LSearchRow)).Value = "Failed" Then

'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy

'Paste row into Sheet2 in next row
Workbooks("ProjSummary.xls").Sheets("Sheet2").Sele ct
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste

'Move counter to next row
LCopyToRow = LCopyToRow + 1

'Go back to Sheet1 to continue searching
Sheets("Sheet1").Select

End If

LSearchRow = LSearchRow + 1

Wend

'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select

MsgBox "All matching data has been copied."

Exit Sub

Err_Execute:
MsgBox "An error occurred."
Next
ActiveWorkbook.Close
Next wbk
End Sub


I am trying to thumb through all of the open workbooks looking for rows containing the word "Failed". Once found, I am trying to paste that row into a summary sheet (ProjSummary.xls) and step down to the next row so that when "Failed" is found in another workbook, it won't past on top of the previously pasted row. I think this code is close, but I am getting some errors. Thanks for the help!
Mar 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
6
by: E Pease | last post by:
I have been trying to edit the Explorer example by Dev Ashish I found on www.msvp.org (I think). I have been all over the net so I am not quite sure where the file came from. I like the way it...
5
by: Jim | last post by:
Hello, I am working on a small windows application for a client, and as one of the functions they want a search that will let them enter a search string, then search a directory for all flies...
3
by: Jennyfer Barco | last post by:
Hello, I have a question, how can I open Microsoft Excel from .NET. I only need to open a new file in Excel and paste some information and set the Microsoft Excel as the enabled aplication, so the...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
2
by: princymg | last post by:
I want to search a file from server and want to copy it to the local disk. how it is done? This is working if the file is in my hard disk itself.But not when it comes to server. If i map the server...
2
by: princymg | last post by:
I want to search a file from server and want to copy it to the local disk. how it is done? This is working if the file is in my hard disk itself.But not when it comes to server. If i map the server...
4
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.