I'm trying to write a macro that will loop to the end of each row, if the last cell is a number it will cut and paste that whole row into another sheet, if the last cell is a word then it will leave it as it is.
I have the code below that clears colums B-J and L-N in whatever row you activate a cell in. When a row gets cleared, how do I shift all the other rows up to eliminate blank rows in between the data real-time? I've deactivated the cut function already since this messes up references in the worksheet, so it would have to only use copy, paste, and clearcontents functions. Also, I don't want to DELETE any rows, just essentially shift the blank rows to the bottom. So when a row is cleared, all others shift up and the blank one goes to the end of the data that is available for data entry, so rows 17 to 116 are always available. But it must check to make sure that B-J and L-N are ALL blank, otherwise some wanted rows with one piece of information might get cleared. So at any given time, my range will always go from row 17 to 116. This is Excel 2007. Here is the code I have to clear rows that can be built upon.
Is it possible to eliminate gridlines from only certain rows, columns and or cells? Specifically, I would like to eliminate the gridlines from the frozen columns and rows.
I have a long list of days and the flight hours of a helicopter in each day. The first two columns are the Date and Flight Hours, at the end of each month there is a space and a cell that says "Total" and may contain other words.
I want to delete every row in which the Flight Hours column contains a 0, a word, or anything that is not a number. This way only the days in which the helicopter has been active will show.
So far I have written a code that deletes every row where there is a 0 in the Flight Hours column, but i would like to delete everything that is not a number, such as a string value, a blank cell, etc...
exclude the duplicate row in the macro. The macro is checking for blank or "NA" in column N and copying the row to a new destination file. It is not repeating the row if either one of the conditions is met. [that is wat I want to do] however if the rows have duplicate data i dont want to copy them.
Sub SRSCheck_Data() Dim Rg_Src As Range Dim LastRow As Long
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.
I have data on 400 rows. Each row has a maximum of 10 cells with data, but many have empty cells with no data. I would like to sort each row to show values of cells in sequence and eliminate empty cells. I can use the sort row function but its a long process for 400 individual rows. Is there an easier way?
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
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..
I have output from mainframe that is copy/paste to an excel workbook. I need to have VBA loop and delete the 15 rows. This is mainframe output so it will always be 15 rows
I've taken over a spreadsheet that has a macro in it. However it doesn't seen to function properly. The big issue with the Macro is that it is only running for the first 80 lines of data. I can't have a restricted range as the number of lines could increase/decrease each month depending on activity. I've attached the code.
Sub Macro1() Dim strTemp As String Dim intSpace As Integer Dim intZero As Integer Dim i As Integer Dim strCat As String Dim strZero As String Dim intLoopCounter As Integer Dim rw, this intLoopCounter = 1 For Each rw In Worksheets(1).Cells(1, 1). CurrentRegion.Rows this = rw.Cells(1, 1).Value ...................
I need to create a loop within a loop. First loop works fine as follows: -------------------------------
x = 0 Dim DirArray(0 To 80) As String Dim intI As Integer For intI = 0 To 80 DirArray(intI) = Range("start").Offset(intI, 0).Value Next
For x = 0 To 80 lob = DirArray(x) Range("lob") = lob Calculate Sheets("WBB LOB Summary").Select ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True Next
---------------------------- At the 'start' point, first loop works downward through rows. Second loop would work across columns in each row within the first loop. I will have to use a variable for 'y' (the across value) b/c the number of cells containing data can vary between 3 & 9, but I have a COUNTA in each row setup to use as the variable.
So spreadsheet data would look like this with A being the 'start' cell: A 1 2 3 B 1 2 3 4 5 6 C 1 2 3 4
I need to pickoff A1, A2, A3, B1, etc, picking up every sub-category on the sheet.
I'm trying to loop through each row in a listbox on a userform and remove the value if it isn't equal to the year shown in a CBYear. i can't sem to figure out what to use in my for statement to point the VBA to the Row as it were
My goal is a macro that exports a .txt file where the user selects desired rows (strains, not necessarily contiguous), header columns (collection data), and a single sequence column. The output format (called fasta) is:
I have a Worksheet with 10K rows where the value for column A is "SMV". There are other rows where the value for column A is "SML". For rows where A1 = SMV, I want to make B1.value = C1.value and clear the contents of C1thru F1 (C1:F1).ClearContents.
No, I cannot sort, cut/paste and resort or put in a helper column with a clever formula (I think) because this Worksheet gets output to a delimited text file by a variety of users.
I use this code to delete some rows, how I would modify it to work in another spreadsheet where it would "Loop" through and delete rows that start with "User:Kellcyna" down to where the rolls start with "Numbers", and delete the rolls that start with "Total cost center" down to where the rolls start with "Numbers".
The data can contain up to 50000 rolls at times.
Sub Finally() Application.ScreenUpdating = True [a:a].AutoFilter Field:=1, Criteria1:="=" [a2:a65536].SpecialCells(xlVisible).EntireRow.Delete If [a1] = "" Then [1:1].Delete ActiveSheet.AutoFilterMode = False [Code] ........
Here is a sample of the data I need the macro to work on. The rows I need deleted are the rows that are highlighted.
User: Kellcyna STANDARD HOURS BY COST CENTER Date: 09/29/2013 Time: 15:10:04 Page: 10
Comments:
Order Op Emp Post Work ctr Setup Unit Planned Earned Total Actual Actual Actual Total Total Orde C R
# Date SU Unit Plnd Stds Setup Run Tme Brd Tme Prod Run Time E
I am stuck with looping columns and rows.What i am trying to do is... I have to loop through columns E3 to G3 and also rows of each column and check for a condition inside the column.How can i achieve that? I have the following structure.. How can i code it?
For i=E3 to G3 'Column loop for j=4 to 47 'Row loop 'code to check if the value isnumber next j next i
1. Delete all data after row 51. 2. Find the average cost (column 4) and delete all rows where the cost is below average. Thus only retaining rows with an above average cost. 3. Then I want to conditionally format any number in column 6 which appears more than three times. 4. I want to loop this through all worksheets in my workbook.
I have an Excel workbook that i need to loop through all rows searching for a certain string we can call "Totals". There are more than one, and i need to grab the values from each at an offset in the same row, different column, to total at the bottom. I have tried a few things unsuccessfully. The code below is just my first step to try to find the row, i know there are problems as i am unfamiliar with the different properties of a given variable.
Function FindRow(szName) As Integer
nFoundRow = 0 For nRow = 0 To Worksheets("Totals").Columns(nCol).Rows.Count If StrComp(Worksheets("Totals").Cells(1, nRow), szName) = 0 Then nFoundRow = nRow End If Next nRow FindRow = nFoundRow End Function
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....................
I have two worksehets. The first worksheet contains data on products. The product code is in column A. My second sheet contains a list of product codes in column a. I want to delete all rows in worksheet 1 where the product code doesnt exist in the list in worksheet 2. Can someone provide a outline for a macro to loop over sheet one and look up the value in worksheet 2 and delete the row from worksheet 1?
'How do I use a FOR NEXT loop on a union to just list all cell values in Col A?
'Just need a little help getting a handle on ranges and the union of ranges. ' This is my first time posting a question so any patience is appreciated.
Dim r1 As Range Dim r2 As Range Dim myMultipleRange As Range Dim xCell As Range
Set r1 = Sheets("Sheet1").Range("A1", Range("A65536").End(xlUp)) Set r2 = Sheets("Sheet1").Range("B1", Range("B65536").End(xlUp)) Set myMultipleRange = Union(r1, r2)
r1.Select
For Each xCell In r1 'Ive been using this type of code to access anything I need from a sheet. Debug.Print r1(xCell.Row, 1), r1(xCell.Row, 2), r1(xCell.Row, 3) Next xCell...............
I need to write a FOR... Next loop that will loop through a range of rows, select the same cell range on each row, perform a task, then advance to the next row. I can't seem to figure out how to substitute the loop counter for the row index. For example:
I have a requirement where I have to add a row with x columns using vba. this is the code I am using now
k = 17 prodetails = .GetFieldValue("Product Details") sSeats = .GetFieldValue("Seats") If isRecord Then While isRecord Sheets("Products").Rows(k).Insert Shift:=xlDown Sheets("Products").Rows(k + 1).Insert Shift:=xlDown Sheets("Products").Rows(k + 2).Insert Shift:=xlDown ThisWorkbook.Sheets("Products"). Cells(k, Prod6Col) = prodetails ThisWorkbook.Sheets("Products").Cells(k, Unit4Col) = sSeats isRecord = .NextRecord() Wend End If
In this code I have declared Prod6Col and Unit4Col as constants. instead I need to use them as variables like in this modified code. However if i use this code, I get an object definition error.
k = 17 m = 20 (20th column) l = 18 (18th column) prodetails = .GetFieldValue("Product Details") sSeats = .GetFieldValue("Seats") If isRecord Then While isRecord
Hello, I am trying to update a person's finances for this past year. She sent me a workbook that has two sheets with macros. The first sheet is linked to the 2nd. When a name and number is typed into the first sheet it automatically shows up on the 2nd.
My problem is, no matter what number I change on the first sheet under amount, the Total cell on the 2nd sheet gives me the #Value error. I have not changed anything, have not deleted any formulas but no matter what I do, that value error always shows up. I know very little about excel but I thought I knew enough to be able to update this book for her. Is there a special way I should be inputting the numbers on the first sheet so that the value error will show the running total instead of an error?
One of the multitude of areas where I still need drastic improvement is with efficiency. Specifically, avoiding loops.
Are any of you aware of any good, basic level sites, blogs, posts, etc., about better methods or processes? I'm not particularly experienced with programming (I've been a software TESTER for 13 years and just started some programming in recent months), so the more basic the better.