VBA - Select And Copy Range Down After Specific Value Found
Nov 28, 2012
I have been trying to write VBA which basicly search for specific value in column A and copy values from that cell to down and two columns next. Select row and columns down after specific value in column A was find.
A B C
... ... ...
X 100 115
... ... ...
up to last row
I try with VBA below but it do not works.
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If Range("A" & i).Value = "9000" Then
Range("A" & Rows.Count).Offset(0, 1).Select
Do While Not IsEmpty(ActiveCell)
I found a macro that searches a column on each worksheet and copies the searched for value to another worksheet but. I would like to modify this to copy the searched for value and the next 10 cells in the row but I am not able to figure out how to accomplish this. I highlighted in red the piece I would like to modify.
For Each sh In ActiveWorkbook.Worksheets With sh.range("c10:c10000") 'this determines where to search
For I = LBound(MyArr) To UBound(MyArr) 'If you use LookIn:=xlValues it will also work with a 'formula cell that evaluates to "@" 'Note : I use xlPart in this example and not xlWhole Set Rng = .Find(What:=MyArr(I), _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then FirstAddress = Rng.Address Do
I have some EXCEL files, titled as "AAA", "BBB", "CCC", so on... Calculated values are placed in Column Z for each file. In order for me to export the files to another software, I would need to create another new EXCEL file (I call it MASS) and place all the calculated values in that new file. In that new file, the titles have to be on Column A and the calculated values on Column B.
For example, File "AAA" has 120 calculated values. In MASS, the word "AAA" has to appear on Column A a number of 120 times and the 120 calculated values are then placed on Column B. Each value must correspond to the word "AAA". The same procedure goes for "BBB", in which the word "BBB" is placed on Column A after the end of "AAA". What I want to achieve is by using a macro that will look up the title of the Active Worksheet and then scan Column A in MASS. If the title matches whatever is in Column A, then the macro will paste the corresponding calculated values onto Column B automatically.
For example, for file "GGG", the macro will look up the word "GGG", scan through Column A in MASS for the start of the word "GGG" and paste the calculated values at the start of Column B. Could I have an idea of how might the macro looks like?
Feedback.xls is the file I want to have my macro run in. By pushing a button to run the macro, it will prompt the user to select where their file is on their computer. This file will have different file names based on the end user. For example sake, I've included CAP.xls.
After the user selects their file, it will prompt them to choose which tab to copy and paste data from. Typically, there will be 30+ tabs on their worksheet. For example sake, I've created 5 tabs on CAP.xls. The tabs in their workbook will be labeled as I have labeled mine, M1 CAP, M2 CAP & M3 CAP. Therefore, it should prompt the user to select which tab to choose from.
After the user selects their tab (M1 CAP, M2 CAP, M3 CAP), the macro should prompt the user to choose which row of information to copy. In CAP.xls, I have a few rows of information to choose from. They all start with FY10A1, FY10A2, FY10A3, but this information could change. Once they select the row, it will copy each of those fields onto the respectively labeled fields on Feedback.xls.
I'm trying to create a macro that can lookup values down a list, find that value within another list and copy the adjacent cells.
The values to look for will always be on the same column and the values to look into will always be in the same range or columns but not always in the same row.
AI:AI contains a list of ID's which will be manually input every day so they might have a different order.
C:AF has all the data to look into. C always being a list of ID values and I want for every ID found on AI:AI to be search for on C:C: and then once a match is found, I need specific adjancent cell values to be copied next to the ID found on AI.
The values that need to be returned are found on columns B,D,F,G,H,I,J,P,AF and they will always display on those columns.
I've been doing this based on vlookup and INDEX/MATCh formulas but I've come across some limitations for something I want to develop further so I'm trying to do this based on VBA.
I need a code that will copy the format AND formulas of the entire row that I have selected (or activatedwith my cursor) to each and every blank row - until it gets to the last row of data on this spreadsheet.Since any employee could have more than 1 row of data - I am using a code that inserts1 blank row after each NEW employee name.
NOTE: This report is initially sorted by employee name so that each occurrence is grouped together.REPORT SPECIFICS:1) This report reflects typical paryoll information.2) Certain columns have data that is either in text, general, or number ($) format3) The number of columns may vary depending on which PR report is being worked4) For the sake of simplicity - we can assume that the column titles will always be across row 15) Each employee name on this report may repeat several times depending on how many weeks they worked,so the SUM() formula should adjust automatically to capture all the rows of data to add up for each employee
HERE IS MY CODE TO INSERT 1 ROW Sub InsertRowAtNewNameONE()Dim LR As Long, i As LongLR = Range("C" & Rows.Count).End(xlUp).RowFor i = LR To 2 Step -1If Range("C" & i).Value Range("C" & i - 1).Value Then Rows(i).InsertNext iEnd Sub
NOTE: See below: I will format and add formulas where I need on the 1st blank row that was createdand I need a code that will copy this particular row to all blank rows to the last.
I have a client list in a table in my excel sheet. I currently enter the clients in a sheet that looks similar to a form. After the clients info is in this Form I have a button with a macro to copy the client info into a table on another sheet. This works perfectly.
Now I have another form that will retrieve the customers info in a click of a button in order to make changes to the client. Ei:I now have a second phone number and I want to update that client's info. What I want to do from here is take the info in Cell B2 (clients full Name), Do a vLookup in the "Saved Clients Table" in a Range within my table range. (Range: Saved Clients and the client's full name is in $A:$A and called "Clients Full Name" and once that name is found I need to select the cell in column C and the corresponding row.
This will allow me to copy the info in my form, Paste it in Transpose to the cell that is selected. (I already have that code)
Here are screenshots of what I am trying to accomplish. [URL] .......
I have a base document that i can import another data document with a button (this is working).
I then have another WS ("search") in the base document with lots of identifiers which I want to use as my search range to look through the document that I just imported (column A).
I need a msg to ask the user what month they would like to find the $ value on (Ie, January) in the imported WS... this way it doesnt copy the entire line only cell in the selected month column.
Then I want to the user to be able to click a button that will check through the identifiers on the "search" WS and if the same identifier appears in the imported WS in column A, then for the $ value in the column selected to be copied to the search Range work sheet.
If the idenfifier is not matched then in place of the $ value copied can be the string "no in XXX WS" .
I have attached the document with dummy data in each work sheet with details more cleary what I have meantion above.
I have a macro to search column E for an occurance of the text ALPHA,(there is more than one occurance of the text, so I'm using a loop to search for the next occurance,once the first one is found. No problems there).
Once I find a Row that contains ALPHA( say Row 15), I want to Copy the columns A15:R15 (NOT the EntireRow).
how I can Copy only a Range of Cells and not the EntireRow?
I want to select only the cells that have colorinterior = 4 (Green)
Dim Cell As Range For Each Cell In [G:G] If Cell.Interior.ColorIndex = 4 Then b = Cell.Address Next Cell
but this code only selects the last cell with green format, my idea is to select the first and the last cell on column G, making b the last cell and a the first cell, to delete afterwards what is between, is there a way on the above code to select only the first cell and not the last one, making the a = first cell and b = last cell?
I am attempting to select a row if the date field value is within a date range.
I would like to be able to click a button, have a pop-up, be asked to insert a start date and an end date. For example 2014-07-01 and 2014-07-21 I would then like the macro to copy rows if the date value is within that range to the next available row onto a new worksheet.
First I will explain what this workbook does. In worksheet "sheet1" I use "change sheet" button to change the backgroud by selecting some pictures, in range S14 I have one number from the name of the background picture (using substiture function). By selecting one cell (with blue text) + one value from the combobox, in worksheet "sheet2" : -the selected value in column A will be deleted - the selected value in column B will be added - in column C I will see the adress of the active cell (cell with blue text) - in column D I will see the blue text from the active cell
I need in column E to copy the range S14 from "sheet1" when I select a value in the combobox ! The range S14 will have different values! I had tried this code (in module1 "Sub test") but it's not working how I need it to work:
I am having a problem putting a range select statement in my macro. Here is what I'm trying to do. I want to select E1, then count down 10 cells below and copy. My sheet is filtered, so those rows are not continues. When I do the record a macro it highlights the rows and it looks like this (e10:e506, but it's only 10 items). I only want it to count down 10 cells and copy. Is there a statement for this.
I have a Macro that already works great but now I need to look for another variable to sort it down even further. I think it can be done by setting up a "Case" but still not sure how to do that. It already looks through the range to find all the rows that return a value of "True". Now I need it sort those results so it only returns what has a specified value in Column "AJ". I am looking to do several choices (Listed Here). So the end result will be all the items that return "TRUE" In Column "AI" and are Items that return one of these values per Case "Starters, Appetizers, Soup, Salad, Entree, Dessert, Special" with then copy over in the exact format that is listed in the code below.
For example All the items that are selected with "TRUE" can be narrowed down to all of those that are "Salad" as well - Then copied over in the exact format that is listed in the code below.
What I am doing is breaking out all the different course of food and putting a Header in-between each (That is already built and working) - So I can select all the food from a master list and then put it in order on the "Catering BEO" Sheet with Headers in between
Code: Sub BEOA4() Application.ScreenUpdating = False Dim wsSource As Worksheet Dim wsDest As Worksheet Dim FoundX As Range Dim FirstFound As String Dim lastrow As Long
I cant seem to get to work together in the same macro but that work great seperated. I need them to be in the same macro. The first just simply copy's text from one workbook to another:
Sub Test2() ActiveSheet. Range("a1").Copy _ Destination:=Workbooks("punchlist.xls"). Sheets("Sheet1").Cells(Rows.Count,1).End(xlup).Offset(1,0) End Sub
That worked ok but I needed to change it to the "active cell" instead of cell "a1". So then this line of code was made:
Dim userInputCell As Range
On Error Resume Next Set userInputCell = Application.InputBox("Use the mouse to select a cell on any sheet", type:=8) On Error Goto 0 If userInputCell Is Nothing Then MsgBox "Cancel pressed" Else Msgbox "You selected " & userInputCell.Address(,,,True) End If
The second code works just the way I want it but it doesnt copy over the text to the other workbook. I assume the 2 codes need to be together but I cant get it to work without errors. I also need the text to copy over without changing the borders on either workbook.
I have a timeline in tab 1. I want to copy a specific cell range from tab 1 to tab 2 but when I make an edit to tab 1, I want it to show up on tab 2 automatically. I believe that's cell referencing but how do I reference an entire range?
I would appreciate some ones help to correct a macro I'm trying to write. The macro copies 3 columns from Sheet1 to Sheet2 in a selected location. The 3rd column copied needs to be pasted in a different column in Sheet2.
I have been trying to create a macro vba that will look at a specific row in the current sheet and if it sees a name I need to delete that row. But I am looking to also under stand what it is doing so I can use this script in other instances. I just bought some things off MrExcel's Store but i won't get this for a few days.
I have a set of data (time in minutes) below (fig 1) that I need to use if the total time between two entered times matches a coloms total. If it matches I want Excel to use the data in that colom to affect the data in another (fig 2) colom adding the times to each cell.
Looking at both figs. below I want Row B, Colom A in fig 2 to add Row A, Col A to Row A, Col A in fig 1 since both are the total of 19.
fig 1 Coloms A B C D Row A 5 5 6 6 Row B 5 6 6 8 Row C 4 5 6 7 Row D 5 4 4 5 Total 19 20 23 26
fig 2 Coloms A B C D Row A 1:00 2:00 3:11 4:01 Row B Row C Row E Row F 1:19 2:20 3:33 4:27 Row F-A= 19 20 23 26
Private Sub CommandButton1_Click() Worksheets("Sheet1").Activate Range("A1").Select Selection.End(xlDown).Select ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate ActiveCell.PasteSpecial End Sub it errors to: SELECT METHOD OR RANGE CLASS FAILED
I would like to use the following code to see if the word "reservoir" shows up in any of the rows in a certain column. If it does I want to insert the formula = SUM(D7:D257)*0.1 into cell C2 and if it doesn't then I want to put a 0 into cell C2. I've tried many routes but can't get past the error if it can't find the word.
That does allow me to filter the output in Master, but ideally what I would want to do is not have to set aside 300 lines in the Master file for each of the Staff files. Conceptually, I'd like to have the spreadsheets Staff A, Staff B, etc. look for and export only lines which have data in them and then have Master bring those lines in automatically. This may not be possible, in which case your suggested solution is the best approach.