Modifying A VBA Code To Del Rows

May 24, 2008

I am trying to modify the below code in order for it to:

1) Check the cells in Column A to find any blank cells and zero values. If the macro finds a blank cell or a zero then delete the entire row.
2) Check the cells in Column D for any blank cells and "N/A" (this N/A is text, it is not an excel error). If the macro finds a blank cell or "N/A" then delete the entire row.

Here is the old code


Sub DL()
Dim lastrow As Long, i As Long
With ActiveSheet
On Error Resume Next
.Columns(3).SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
On Error GoTo 0
lastrow = .Cells(Rows.Count, 3).End(xlUp).Row
For i = lastrow To 1 Step -1
If .Range("C" & i).Value = 0 And .Range("D" & i).Value = 0 Then .Rows(i).Delete
If .Range("C" & i).Value = "N/A" Then .Rows(i).Delete
Next i
End With
End Sub
Here is the modified code...


Sub DL()
Dim lastrow As Long, i As Long
With ActiveSheet
On Error Resume Next
.Columns(3).SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
On Error GoTo 0
lastrow = .Cells(Rows.Count, 3).End(xlUp).Row
For i = lastrow To 1 Step -1
If .Range("A" & i).Value = 0 And .Range("A" & i).Value = "" Then .Rows(i).Delete
If .Range("D" & i).Value = "" and .Rang("D" & i).Value ="N/A" Then .Rows(i).Delete
Next i
End With
End Sub

1) Is this the correct and efficient way to accomplish the task?

2) How to i change this in order to select a specific sheet?

View 9 Replies


ADVERTISEMENT

Modifying VBA Code

Feb 16, 2009

This code works great for me, but I need some help modifying it. This code searches for data in the whole sheet, two things I would like to do is limit the search range to one column and then to find the whole string, not partials, for example, find 331 without finding all the 33's or 31's.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
If Target.Address = "$A$1" Then
Set MyRange = Cells.Find(what:=Target.Value, After:=Target)
If Not MyRange Is Nothing Then MyRange.Select
End If
End Sub

View 9 Replies View Related

Modifying A Small Peice Of Code

Nov 23, 2007

The following code is a is designed to paste into "Y1", the value in column 5 of the active row when that cell is changed. This works perfectly if I select the value from a dropdown list and hit enter, or if I enter a value manually and hit the right or left arrow key. However if I manually change the value of the cell and then hit enter, it does not work because it looks for the value in the next row.

Does anyone have any idea what I can do to make the macro stay focused on the cell who's value changed even if I hit enter?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim AR As Long 'Active Row
AR = ActiveCell.Row
If Target.Column = 5 Then
ThisRow = Target.Row
If ActiveCell.Value > 0 Then
Selection.Copy

View 9 Replies View Related

Result Error After Modifying Code

Dec 4, 2008

The following codes work well but when I have changed the following condtion ,

If cel = Tgt.Range("A2") Then
to

If cel "" Then

I got worng result, can anybody help me to correct it?



Option Explicit
Sub test()
Dim sh As Worksheet, Tgt As Worksheet, i As Long, j As Long
Dim d, a
Dim c As Range, Rng As Range, cel As Range

Set Tgt = Sheets("Report")
Set d = CreateObject("Scripting.Dictionary")
j = 0
On Error Resume Next ...............

View 9 Replies View Related

Modifying Code To Reference Cells And Its Formatting?

Aug 7, 2012

I am attempting to modify the code below to, not only reference the ".Item(rCell.Value)", but also include it's formatting. The format for that referenced cell will not necessarily be a "certain" format..so I don't want to have to write out what specific formatting needs to happen.

VB:
If (.exists(Trim(rCell.Value)) And rCell.Offset(, 1).Value = "") Then rCell.Offset(, 1) = .Item(rCell.Value)

The entire code is as follows:


VB:
Sub FillVariablesOnlyBlanks()
Application.ScreenUpdating = False
Dim a, i As Long, rCell As Range, ws As Worksheet[code]....

View 9 Replies View Related

Modifying VBA Code To Generate 4-digit Numbers?

Mar 19, 2013

modifying the following VBA code; this code auto-generates 4-digit unique numbers, using zero as one of the starting digit as well. I need the 4-digit numbers NOT to begin with a zero, the 4-digit numbers should only begin with numbers 1-9.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
Dim Test As Integer

[Code]....

View 2 Replies View Related

Find And Replace Macro - Modifying Code In Engagement

Jan 27, 2014

I am trying to make a find and replace macro for multiple items.

Please see the attached file for further explanation : macro.xls‎

View 3 Replies View Related

Deleting Rows Without Modifying Formulas

Apr 9, 2009

I have a large amount of data on a sheet which is being looked at by the following formula

{=AVERAGE(IF(LEFT(RAW_DATA!$C$4:$C$10000,LEN(Dashboard!$I$10))=Dashboard!$I$10,IF(RAW_DATA!$A$4:$A$10000=$A2,RAW_DATA!$J $4:$J$10000)))}

However, i don't need to keep the oldest data so I want to write a macro that deletes some of the top rows. Doing this in the normal way causes the formula above to change. I.e deleting one row cause the range to become $J$4:$J$9999 and so on.

Is there any way of deleting a row without affecting the formulas that are looking at it?

View 9 Replies View Related

Modifying Data Before Pasting

Nov 6, 2008

I am copying some data from one workbook and pasting the data into another workbook depending on certain criteria (using autofilter) using excel VBA. For only One column i need to multiply data by 100 (i.e. convert it into percentage) For example column A in source worksheet has all values and i will paste it in column D of target worksheet. But before pasting i need to multiply the data by 100 so column D in target worksheet has values in %.

View 3 Replies View Related

Modifying Entries Into 1 Line?

Jan 24, 2012

I need a way to take the below example and combine each entry into 1 line.

ALRSItem Number/QuantityStockingDescription On HandUnit Actual Cost170PC1832PCB1un43.75circuit de PC1832 nouvelle version 5010 (P832)Avg. Unit Value:43.750000Costing Method: Moving AverageCosting Unit:un250282un2.05Braquette pour contact anti-vandale 112 ADEMCOAvg. Unit Value:1.025000Costing Method: Moving AverageCosting Unit:un

I would like to take each part and place the specific part information provided into 1 line for each part number.

View 1 Replies View Related

VBA Oddity, Modifying For Loop

Aug 8, 2007

It's refreshing to know that to make VBA even more lightning fast it doesn't check the For limiting variable. /sarcasm mode off

Does the following surprise anyone? Surprises me. (And yes, I know what an Exit For is. This code is designed solely to illustrate the point.)

Sub JimmyLoopVar()
Dim i As Long, K As Long
K = 6
For i = 0 To K
If (i > 3) Then K = 2
Debug.Print i; ; K
Next
End Sub
So the loop runs 7 times regardless of K! (At least on XL03 )

View 9 Replies View Related

Writing/modifying An Macro

Oct 18, 2007

Every month I download a report from a state agency that I need to reformat, create charts from and send reminder emails based on some of the data. The report is downloaded as an EXCEL workbook containing a single worksheet. The worksheet is preformatted as a printed report. I have no control of this formatting and I can not get the data as a .csv file. The report contains 3 sections. See detailed report description below.

What I want to do:
1.Is copy the 3rd section of the report to a new worksheet.
2.Sort the new worksheet by name, and date.
3.Filter some names based on resource type.
4.Create a new file, which will be attached to an email to my boss for follow-up.

Originally I used the built-in EXCEL macro recording function and this worked for a couple of months. Then the number of rows in the 2nd section varied and my generated worksheet failed to sort correctly, and I lost the column headings so my filter no longer worked. The results were not something I could forward. I do not know how to modify the macro to search for the literals which end section 2 or start section 3 so I can copy the correct data to the new worksheet. I am not a VBA programmer, just an old-fart trying to do some administrative volunteer support for an important program, and really do not want to become one.

Detail Report Description:
Section 1: Headings –contain fixed headings in merged & centered cells.
Row 1 – Report heading 1 in merged cells A1–I1
Row 2 – Report heading 2 in merged cells A2-I2
Row 3 – Report heading 3 in merged cells A3–I3
Row 4 – Blank row............

View 9 Replies View Related

Conditional Formatting (VBA) - Needs Modifying

Jun 28, 2006

Basically my code works fine if I enter a number into the reference cell. But for my actual application, I need it to update the reference cell's background color when I enter other data. B21 has a =IF(COUNT(B18, B19, B20) < 3,"",B18 * B19 * B20) statement. So as I modify B18, B19, B20 it should update B21's background color. Here is the VBA:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B21")) Is Nothing Then
If Target < Worksheets("OEE Data").Range("K6").Value Then
Target.Interior.Color = vbRed
ElseIf Target >= Worksheets("OEE Data").Range("K6") And Target < Worksheets("OEE Data").Range("L6") Then
Target.Interior.Color = vbYellow
ElseIf Target >= Worksheets("OEE Data").Range("L6") Then
Target.Interior.Color = vbGreen
Else
Target.Interior.Color = vbWhite
End If
End If
End Sub

Obviously my VBA isn't sound and hence won't apply any background to B21. If I just change it to AA1 and enter the criteria into AA1, it's background changes without problem. The reason I need this in VBA is because in the cFormatting I need the first condition to be 'is equal' ="" (white background) or it defaults my BLANK CELL to being > 1 (Green background). This is why I need 4 conditional statements.

View 2 Replies View Related

Modifying Text Within A Cell

Jul 19, 2006

I have imported text from a database that has names shown as "last name, first name" in a single cell and am trying to figure out if it is possible to modify those names to "first name last name." I would also like to see if I could just have the first name transferred to a different cell.

View 3 Replies View Related

Encountering Error When Modifying A Formula

Jun 2, 2014

Below is a formula that I am attempting to modify:

From this:
=IFERROR(IF(A8<MIN(A$8:A$30)+365*5+1,(IF(AND(A8>=$E$4,A8<=$E$5),1,0)*B8*(MAX(C8,D8)/365)+B8),(IF(AND(A8>=$E$4,A8<=$E$5),1,0)*B8*(D8/365)+B8)),"")

To this:
=IFERROR(IF(A8<MIN(A$8:A$30)+365*5+1,B8*(MAX(C8,D8)/365)+B8),B8*(D8/365)+B8)),"")

But it is giving me an error result.

View 2 Replies View Related

Modifying Macro - Pasting Over Row Of Data

Aug 11, 2014

Macro (see below).

I have two sheets 1) ap modified 2) gl download

It's merging the two sheets together. however, it's pasting over the last row of data. For example, gl download has data from row 4 to row 100. The Macro is pasting data from ap modified starting in row 100 of gl download instead of row 101. How can i correct this?

Sub C_Merge()
Dim w1 As Worksheet, w2 As Worksheet
Set w1 = Sheets("ap modified")
Set w2 = Sheets("gl download")
Dim lr1 As Long, lr2 As Long

[Code] .........

View 3 Replies View Related

Modifying Formula To Get First Part Of Postcode

Mar 7, 2012

I have this function that checks a postcode and returns a value using the first part of the postcode.

What i would like to know is how to modify the function so if there is only the first part of a postcode already entered, it looks for that.

At the moment sometimes i get #N/A even though i know that value is in there.

Code:

=INDEX(U$4:U$1068,LOOKUP(1068,MATCH(IF({0,1},LEFT(B338,FIND(" ",B338)-1),LEFT(B338,1+ISERR(MID(B338,2,1)+0))),T$4:T$1068,0)))

View 1 Replies View Related

Modifying Contents Of A Cell Using Other Cells

May 27, 2013

I do not have excel or an xls for a sample, I will try and restate the question.

In Cell A1 It will be used for copying the contents of and pasting the completed information into web browsers.
In Cell A1 You will find This information contained and formatted in one cell alone.

Figure-1
A1=

Information About Company
Brief Story About Company
Product Name: (X)
UPC Number: (Y)
Serial Number: (Z)
Terms Of Sale
Etc

End Figure-1

I want to essential Modify (X)(Y)(Z) using different cells one for each variable. "All completed information will be found inside of A1"

Having Cell B1-B9 Being used as labels "Product Name" "UPC Number" "etc" and using cell C1-C9 to input variables for = (X)(Y)(Z)(ETC)

In reality from cell A1 will change dynamically, but some information will need to stay constant.

Every thing In B column will just be labels.
Every thing In C will be for variables.

View 1 Replies View Related

Modifying Accounting Custom Format?

Oct 31, 2013

I'm using this custom format

Code:
_-£* #,##0.00_-;[Red]_-£* #,##0.00_-;_-£* "-"??_-;_-@_-

How do I modify it so that if the value is 0.00 then 0.00 is showed and not the current "-"?

View 3 Replies View Related

Modifying Macro - Accounting Analysis

Jan 18, 2009

I have the macro shown below, which I found in a 2003 issue of the journal of accountancy - and it works great. However, it only works on a data set that begins in cell A1. I want to incorporate it into a spreadsheet I have where my data set begins in cell E15 and goes down from there(column E will be the only column that this macro will need to run on and I need it to work on a data set that will vary in length). This macro performs a Benford analysis, which analyzes the first and second number of a data set.

Dim Arrayone(0 To 9) As Integer
Dim Arraytwo(0 To 9) As Integer
Dim Arraythree(0 To 9) As Integer
Dim Arrayfour(0 To 9) As Integer
Dim Arrayfive(0 To 9) As Integer
Dim Arraysix(0 To 9) As Integer
Dim Arrayseven(0 To 9) As Integer
Dim Arrayeight(0 To 9) As Integer
Dim Arraynine(0 To 9) As Integer
Dim Arrayzero(0 To 9) As Integer
Dim Arraytwotest(10 To 99) As Integer

Dim x, I

Dim Row As Long, Col As Long, Step As Long, Colcells

Dim Digits As Long, Total As Long

View 9 Replies View Related

Code To Delete Rows Based On Status Code In Column

Jul 24, 2009

I'm trying to write a VBA script which will delete all rows in my Excel spreadsheet where Column I (which contains a status code) does not contain the word "Completed".

At the moment, I'm doing this the other way round: my script is able to search for entries in Column I which contain the status codes "Pending", "Awaiting Authorisation", "In Progress" etc and delete them. The idea is that when all those rows are deleted, I'll only be left with rows which have a status of "Completed". This works fine at the moment. However, the concern is that if a brand new status code is added to the data file, my script would be unable to pick it up and delete it. This is a small sample of the code I'm currently using (which deletes all the rows with statuses other than Completed):

View 4 Replies View Related

Modifying Lookup Formula To Get Relevant Data

Apr 22, 2009

I am trying to do what I thought was a simple look-up. On one sheet in colum A I have some text and in colum B I have a number. On a second sheet i have a list of text that may or may not match the text on the first sheet in colum A. If the text in colum A matches one of the text items in the list, I want to have the value in colum B appear next to it in colum C. I tried to modify a vlookup formula but would only get a value error if there was a match.

View 3 Replies View Related

Modifying Current Script To Look For Blank Cells?

Jul 25, 2013

Below is my current code, what I would like to add is once the user presses Yes it also verifies that "Sheet TEOD" has all cells filled out in the Range("E6:E14,E17:E28,E32:E35,E39:E51"). I just want the code to stop and say that "Sheet TEOD" not complete. Otherwise if there is something in that range it verifies the next sheet which is already there and sends.

View 1 Replies View Related

Getting And Modifying Data From Specific Row Within A Sheet With Userform

Jul 11, 2014

I have an excel sheet with a few buttons which open up separate user forms:

The first button "Add Exhibitor" works by bringing up a user form which enters data into the separate excel sheet called amends in the next available row, the data is initially selected by a stand number which if it already exists in the "amends" sheets brings up an error.

The second button "Modify Exhibitor" is what i am having the problem with. When the user clicks this button it brings up an identical form but for modification. What i need it to do is when the user selects the stand number in the drop down box: For example: H1-A-01, i need it to pull the data from the row in the "amends" data sheet which matches that stand number and put it into the user form so the user can modify and make changes, i would ideally like to be able to track these changes as well.

I am new to VBA and have tried many things so far online, i have managed to get the company name from the correct row and column to work but i cant figure out how i did it or how to make the rest of the data do the same?

The code i am using is below & an example of the form with data removed can be downloaded from here: [URL] ....

[Code] .....

View 2 Replies View Related

Modifying VBA Function To Search Only Complete Words?

Mar 19, 2014

I've been working on a method to search a single column of 1000+ cells containing a paragraph with a 250+ word keyword list (also in a single column). I'm needing only complete words to be searched/ displayed regardless of spacing & punctuation. I've tried multiple methods the past few days and the one that worked (Macro with 4 complex formulas) was unusable when scaled out to all 1,000 rows due to the extremely long calculating time. I don't know VBA yet but was able to modify and create a user defined function that does everything I need except it displays string results that are not whole words (Ex. search for air, word in cell is fair, displays a result for air).

PHP Code: 

Function RangeSearch2(text As String, wordlist As Range, seperator As String, Optional caseSensitive As Boolean = False)    
Dim strMatches As String    Dim res As Variant    Dim arrWords() As String    Dim skip As Boolean    skip = False    
On Error Resume Next    Err.Clear    For Each word In wordlist            If caseSensitive = False Then      

[Code] ...........

View 4 Replies View Related

Merge Two Worksheet Into 3rd Sheet (modifying A Macro)

Jun 2, 2008

i have three worksheets: "List 1", "List 2" and "New ist".I want to merge the first two sheets into third.

List 1:

View 14 Replies View Related

Modifying Existing Calendar User-form

Aug 10, 2009

I got this attached sheet from this very forum. I was wondering is there a way out that the pop out calendar could show two months calendar i.e as now when i click on the calendar button it shows up August's calendar, i want it to show up August's as well as next month's (September) calendar also but in the same window.

View 8 Replies View Related

Modifying A Format Cell :: Phone Numbers

Oct 22, 2008

I'm trying to change a
418,3315555
format cell to a regular phone number cell
418-331-5555

View 9 Replies View Related

Modifying A Sumproduct Formula To Search For Words In A Cell

Jul 7, 2009

My current formula is this: =SUMPRODUCT((Str311A=1)*(Str311C=15)*(Str311G<>" DM "),Str311L). All the items starting with Str311 are formula's associate with a name. What I'm trying to do is add one more factor into the formula. I need it to look in column I for any cell that contains the words L/S. I tried modifying the formula to this but it does not work:

SUMPRODUCT((Str311A=1)*(Str311C=15)*(Str311I="*L/S*")*(Str311G<>" DM "),Str311L)

The formula contained inside the names are:

Str311=OFFSET(Outlet!$A$1,MATCH("STORE # 163311",Outlet!$A:$A,0)-1,0,MATCH("TOTAL FOR STORE : 163311 SAN MARCOS",Outlet!$A:$A,0)-MATCH("STORE # 163311",Outlet!$A:$A,0)+1,1)

Str311A=OFFSET(Str311,0,0)

Str311C=OFFSET(Str311,0,2)

Str311I=OFFSET(Str311,0,8)

Str311G=OFFSET(Str311,0,6)

What I need is a way to modify my original formula to now also only match cells that contain the phrase L/S. The phrase can be located at the beggining, middle, or end of the cell characters.

View 2 Replies View Related

Modifying Concatenation Formula - Put A Space If Cell Is Blank

Jul 4, 2013

How would I modify this concatenation formula:

Code:
=concatenate(A2&" "&B2)

I would like it not to put a space in if A2 is blank.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved