Loop Through Rows & Copy Each Row To New Workbook
Aug 27, 2008
I have some data for my students in the range D2:G251, where each row is a different student. I need to write a macro that, if there is an 'x' against their name in column D, will copy the data in columns E-G into range A1:B500 and copy that range into a new workbook and save the workbook with the students name. The following code does this for the first row, but I don't know how to write a loop (or whatever) to make it do it for the other 249 rows.
Private Sub CreateNewSheets_Click()
Dim ws1 As Worksheet
Set ws1 = ThisWorkbook.Sheets("Template")
Dim Rng1 As Range
Set Rng1 = ws1.Range("A1:B504")
varPath = ThisWorkbook.Path
If ws1.Range("D2") = "x" Then
ws1.Activate
ws1.Range("e2:g2").Copy
ws1.Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
Rng1.Copy
Workbooks.Add....................
View 6 Replies
ADVERTISEMENT
Feb 8, 2012
I am looking to copy a row of data from a worksheet to another closed workbook.
Basically i want the macro to look at the sheet "Register" and copy each row as long as it is not blank to another workbook in a shared folder, and find the next blank line.
macro would be
if "register" value in A2 is not blank copy row to next blank row in D: est.xls sheet data
loop until all rows copied
View 5 Replies
View Related
Aug 27, 2012
I need VBA code for the following - I have a worksheet with seven colums of data (A to G) - I need to copy the first column (A) from the active worksheet then open master workbook called 'master' and paste the data in to column D - then save the 'master' as the name in cell Z1 of the 'master' workbook. Once this has been been completed I need to repeat the process but this time copying column (B) and so on.
View 4 Replies
View Related
Mar 16, 2014
I have a workbook, in which from sheet1, I have to copy first row and paste it in another workbook in sheet1 This I have to do for all the rows present in first workbook. I have written code for one single row, but for all rows,
below is the code :
Option Explicit
Dim wbIP As Workbook
Dim wbJT As Workbook
Dim wbET As Workbook
Dim mypathET As String
Dim mypathJT As String
Dim mypathIP As String
Dim vals As Variant
[Code]...
View 1 Replies
View Related
Apr 3, 2007
I have a table of data 100's rows 10 cols. In col A is a name like USA - these refer to sheet names in the workbook. The other cols are numbers.
I need to write a macro to start at row A and go down the rows 1 at a time and copy and paste that row to the bottom of the sheet named in Col A.
Actually needs to insert at the bottom of a table in the USA col rather than just paste as there is other data further down.
View 9 Replies
View Related
Jul 26, 2009
I have one column of names in excel. The column may contain more than one row with the same name but these rows with the same name will all be grouped together. This is an exampe (each name represents a row in column A):
ColumnAColumnB
andrewData
julieData
julieData
julieData
jonathanData
jonathanData
What I want to do is copy the rows with the same information, e,g, the rows with 'julie' above, paste them into a new spreadsheet and email this spreadsheet to specific email addresses and then do the same for 'jonathan'.
I can work out how to send an email using VBA but I am really stuck as to how to go through the rows and send the email in discrete 'chunks'. I have tried using a for next loop, looping through the rows and copying/pasting rows that are the same as the previous one into a new spreadsheet but this does it one row at a time.
If I include the instruction to email the spreadsheet within the loop this would also email the new spreadsheet one row of information at a time, i.e. three emails for 'julie' each containing a spreadsheet with one row of information on it, rather than one email containing one spreadsheet with all three rows on it.
View 4 Replies
View Related
Dec 13, 2006
I have 2 workbooks.
The first one (Top Ten Auto Generator.xls) ( Sheet is Summary) has 1 row (13) with 4 cells that have data. A13 with date (today formula), B13, D13, and E13 are numbers. The cell range will be the same each time the data is copied (the workbook has a marco to generate the numbers each day already).
The date doesn't need to be copied, just the other 3 cells data (in the same order) using paste special.
The workbook that needs the cell data is a report ( Dashboard.xls) that has lots of different departments each using 3 columns for their specific data. The left most column A is the date listing to match.
The column Range for my department on that "Raw Data" sheet is "H", "I", & "J" where the "H" would get the data in "B13", "I" would get "D13", "J" would get "E13" for the date that matches the other workbook.
So the way it would work, is that once the vba is run the 3 cells from the auto generator are copied, then the vba opens the dashboard.xls and looks for the date in column A which matches the other workbooks A13 date value, and then the cells are pasted into that row, but in column H, I, & J.
Here's sort of some code that I put together to see if that would be easier to understand. I'm new at doing the vba so I don't have better code.
Private Sub CommandButtonpaste2dash_Click()
'get our data from generator
Windows("Top Ten Auto Generator.xls").Activate
Sheets("Summary").Select
Range("B13,D13,E13").Select
Range("E13").Activate
Selection.Copy
Workbooks.Open "Dashboard.xls"
Sheets("Raw Data").Activate
'look for the date in column A which matches A13 in the Auto generator
Some Code For finding the right date
'once found, paste special to the same row, but in column H (the 3 cells should paste together ok)
some code For pasting into H In the same row As the found date
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
ActiveWorkbook.Save
MsgBox "Done!!!"
End Sub
View 9 Replies
View Related
Mar 3, 2007
I am trying to copy a single row from a number of workbooks (that are closed) into a summarized workbook (that i have open) with each row being in the next row down in the summary workbook worksheet 1. I am having trouble with the .open and setting the destination workbook because i want the info to go into an already open workbook.
I have written the following code which brings up errors..
Sub Summarize()
Dim Counter As Long
Dim Source As Workbook
Dim Dest As Workbook
Const MyDir As String = "H:VickyexcelDave"
Application. ScreenUpdating = False
Set Dest = Workbooks.Open(MyDir & "davesresults.xls")
For Counter = 1 To 100
View 6 Replies
View Related
Sep 27, 2006
I need to copy data from one sheet to another in the same workbook. The data is never the same and can change without notice. Here is what I need to do:
The trigger will be in column A with the cells content being 1 through 85 (never all 85 numbers though, mostly 1 to 10 sheets need to be created). As I said it is not consistent and sometimes new ones are added or some are deleted. For instance, if you find a 1 in column A1 and there is not a sheet named "1" then create it and copy all of the rows that have a 1 in column A. When column A changes to another number say 5, create a new sheet and redo the above until all is copied into separate sheets. My problem is that I don't know how to create a new sheet when the number in column A changes.
View 2 Replies
View Related
Nov 28, 2007
Currently I have two files: Samples.xls and RefSamp.xls. RefSamp.xls currently contains data from Samples.xls and Samples.xls is updated periodically. As samples.xls continually updates I would like to copy to RefSamp only the lines that have not been previously copied over (perhaps some sort of pointer to be used?)
Some of the lines from Samples.xls are removed and/or edited after I have them in RefSamp, which is why I do not wish to copy all the data over each time.
View 9 Replies
View Related
Sep 11, 2013
I have working code that returns a row number within a for loop based on parameters I set.
Each time the for loop runs I would like to store this row number, then after the loop has finished, delete all stored rows.
Code:
for rowNum = 1 to x (some variable end row number which I already have worked out using End(xlUp).Row)
if x = y then
*storedRow = rowNum
end if
next rowNum
*
Lines with a * are the bits I can't work out. I've been trying to understand arrays by reading posts on what other people have done, but I can't fit (or fully understand) the reDims, or reDim preserves into my code. I've seen what appear to be quite complex ways involving uBounds and LBounds, but unfortunately I can't see how to use them.
All I want is to simply keep adding a row numbers to a variable, (i.e. row 2, 5, 20, 33, 120, etc) and then delete those specific rows.
View 4 Replies
View Related
Feb 7, 2008
I have some numbers in a column that I need to copy 12 times (each one) into another column. The problem is that I got like 200 records that will be converted in 15000 aprox. I've uploaded an example of what I need,
View 3 Replies
View Related
Aug 4, 2009
I have been struggling to setup these two workbooks for a bit now, and I can't for the life of me figure out a formula to do what I need to do. Essentially, I have one workbook that contains a list of purchase records for my company, sortable by Date, Vendor, Price, etc. and one workbook that has a sheet for every vendor. What I need is a formula that will search column B for a vendor, Allied Waste for example, and transfer all the information within the rows for every instance that vendor is found to the new workbook.
This is basically just a way where I can input information once in one workbook, where the sheets are divided by month, and the info will automatically transfer to another workbook, where the sheets are divided by vendor.
View 2 Replies
View Related
Mar 9, 2012
I'm looking for a macro that can do the following:
Contact
First Name
BD
Case
XXXXXXX
Aaron
A
XXXXXXXXXXXXXXX
XXXXXXXX
Abigail
C
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXX
Accounts
D
XXXXXXXXXXXXXXX
XXXXXXXXXXXXXX
Adam
C
XXXXXXXXXXXXXXX
Filter by BD 'C'
Copy all rows containing 'C' to new workbook.
Save new Workbook as 'Mailing C.xls' and close to specific flolder.
View 7 Replies
View Related
May 23, 2006
I have a workbook made up of 10 worksheets or so. Each of the rows in each worksheet includes the age of a case in column H. I want to copy the rows that show a case that is over 90 days of age, I then want to paste these into another worksheet. I want to do this for each of the ten worksheets.
View 6 Replies
View Related
Jun 28, 2014
I have a workbook with many (25) worksheets which all have the same structure, column headings, etc. but vary as to the number of rows. I would like to search all worksheets in workbook and copy to worksheet "120" only those rows where column C is "120" and column E is "1-00053-".
Ideally, input boxes would be used to enter these criteria so that it can be used for different scenarios in which these values will vary.
View 1 Replies
View Related
Apr 21, 2014
Copy rows from one Sheet to another based on a separate cell value But specifically, I am trying to copy row values from Columns C through column Z in Worksheet 1 of file POHeader.xlsx to row values Columns N through AK in file POReceiv.xlsx when the (Purchase Order #) values in Column A of each file match.
The reason is behind this is - one file has the unique Purchase Order number as the key without associated parts and the other file has the associated part number as the key with purchase order number attached.
I don't know whether I need to use VBA or if I can just use an index and match function.
View 9 Replies
View Related
Dec 7, 2009
I'm trying to copy Rows from a worksheet ("sheet1") in Workbook ("SourceData") to another workbook ("Final") and worksheet ("Regions") based on critieria selected in a listbox ("Listbox" located in a user form in "Final". The listbox selection is pasted in another worksheet, "Steps"). The trick is, the selection can be a single choice (Region2) or multiple choice (such as Region1, Region 3 and Region 7) and I'd want to copy any rows containing the selection criteria. I've got a bare bones start, but I can already see it's going to give me trouble. Here's what I've got:
View 9 Replies
View Related
Jan 30, 2013
I have spreadsheet of data, I need to extract any rows that have blanks cells in columns F or P or T.
If possible I would like a macro I could run that would cut all of the rows that meet the above criteria and paste them in to a separate sheet.
View 2 Replies
View Related
Dec 11, 2011
I am using Excel 2007
I have a spreadsheet with 1,000 rows in multiple columns
In column "B" i have 8 unique names.
What I am trying to work out is to copy and paste all the rows for each unique name and save in a separate workbook named as the unique name.
View 2 Replies
View Related
Apr 22, 2012
Using excel's text to speech I've put together a basic spreadsheet.
[URL]
Code:
Function talkit(Speech)
Application.Speech.speak (Speech)
talkit = Speech
[Code]....
View 9 Replies
View Related
Jan 28, 2009
I have a small macro that searches the sheets in a workbook and sends the info (if qualifies) to a new workbook before saving that workbook using a name date time format for records.
I woud like this macro to be able to repeat action in 8 more selected workbooks in a folder.
Question - can I name the workbooks I want to search - and - can I search all 9 workbooks before the data sheet saves and names itself, limiting access.
View 13 Replies
View Related
Feb 27, 2013
Is it possible that a VBA code could loop through some sheets in a workbook and save each one as an individual CSV file. The CSV filename would be the same as the sheet name.
View 2 Replies
View Related
Jan 4, 2008
i'm tyring to formulate a do loop that will basially loop until the workbook is opened. here is my code...
'CHECK IF OPENED WORKBOOK EXISTS
Dim myBook As Workbook
On Error Resume Next
Set myBook = Application.Workbooks(vCriteria & "ISPR.XLS")
On Error Goto 0
what i want is for it to loop until myBook is <> nothing... but i'm not sure how to do that.
View 5 Replies
View Related
Dec 21, 2009
However it will only add data to the active sheet when i am asking it to loop through the workbook missing out specified sheets. Would anyone be able to look over the code to see where the error is as to why it will not loop through the remaining sheets in the work book.
View 5 Replies
View Related
May 29, 2008
I am trying to loop a procedure that changes a cell value on 2 sheets in a workbook. I recorded a macro on one workbook and it worked fine. I then tried to modify the macro to loop this on more workbooks that have identical worksheet names. The macro is in a workbook named LIST, which column A has a list of all the workbook names. Currently there are 55 workbooks, but in the future I am sure there will be a few more. Here is a copy of the macro:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 5/28/2008 by MT
'
Dim STATEstr As String
Dim a As Long
a = Range("C1")
For STATEstr = A1 To A55
Workbooks.Open Filename:="C:ALLSTATES" & STATEstr & ".XLS"
Sheets("3 ANL").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = a
Sheets("3 ANLV").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = a
ActiveWorkbook.Save
ActiveWindow.Close
Next STATEstr
End Sub
The first error I got was a TYPE MISMATCH on 'For STATEstr = A1 To A55'.
There may be more things wrong with this looping. The only experience I have with macros is recording them and then modifying and combining them.
View 9 Replies
View Related
Apr 21, 2006
am using excel to go to a web site and download a series of pages
www.abc.com/1
www.abc.com/2
etc
However, if the requested page doesn't exist I just want excel to ignore that and carry on. So I have...
For f = 60000 To 100000
Workbooks.Add
mtch = f
gp = Left(f, 2)
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.cricketarchive.com/Archive/Scorecards/" & gp & "/" & mtch & ".html", _
Destination:= Range("A1"))
.Name = f
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True..........................
but excel still returns a message box saying it couldn't open the requested page when i just want it to skip to close workbook and loop. i have to hit 'debug' and move next line to where i want.
View 5 Replies
View Related
Jun 15, 2007
I am automating a spreadsheet. I want to be able to take all values of product 1 from column a and then add the corresponding values of units and dollars in the adjacent columns.
So I would like a list with each product at the bottom, and corresponding units and dollars, yes I know I can use formulas and pivot tables, but I would like to automate this
The problem is that my loop works for the first product, but it will not go again for the next one.
Here is my code and spreadsheet with code in it, try it to see
Sub rowadd()
Sheets(1).Activate
Dim LastCell As Range
With ActiveSheet
Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
If IsEmpty(LastCell) Then
'do nothing
Else
Set LastCell = LastCell.Offset(1, 0)
End If
End With
View 9 Replies
View Related
May 15, 2007
I have a problem with the next code and i don't know how can i solve it... i have a workbook with 8 columns and variable rows per day... This workbook has 2 sheets. What I want to do is find in the first sheet all the rows that in column E have the number 570 or 640, and after this, choose some of the columns and copy them in another sheet repeating this all the time until the last row... and copying in the next row of the other sheet, starting in the 20th...
LastRow = Range("A65536").End(xlUp).Row
Dim i As Integer, j As Integer
For i = 2 To LastRow Step 1
If Cells(i, 5) = 570 Or Cells(i, 5) = 640 Then
For j = 20 To 26
Cells(i, 2).Copy Destination:=Sheets("Final").Cells(j, 1)
Cells(i, 4).Copy Destination:=Sheets("Final").Cells(j, 2)
Range(Cells(i, 6), Cells(i, 8)).Copy Destination:=Sheets("Final").Cells(j, 3)
Next j
End If
Next i
View 3 Replies
View Related
Feb 18, 2014
My workbook contains four sheet: input, letter 1, letter 2, data
Data contains customer records, column A is numbers 1-500
Input sheet is a customer form containing details for 1 customer. The customer details are pulled from the data tab using vlookups based on a value in cell a1 on the input tab.
Letters 1 & 2 are letters to a customer. They again use vlookups to populate various fields on the letters with the customer information on the input sheet.
What I need:
A macro to populate the input form by working down the records on the data sheet. when the input form is populated with customer information it is to export the letters as a pdf and then move on to the next row of customer details.
I have the export to pdf macro, i just cannot get the input form to loop through the customer records..
View 1 Replies
View Related