delete columns if 0

i am using the following code to delete the complete row:

        Range("B:B").Select
            Selection.AutoFilter Field:=1, Criteria1:="0"
        On Error GoTo line1
        With Sheet1.Range("b:b")
        Cells.SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End With
line1:

what i need is to delete only columns a:g (not the entire row) if the value 
in column b = 0.  

any help is appreciated.

jat
0
jatman (2)
1/1/2009 10:50:07 PM
excel.newusers 15348 articles. 2 followers. Follow

2 Replies
597 Views

Similar Articles

[PageSpeed] 2

Try some code like the following. Change the line

Set WS = Worksheets("Sheet1") '<<< Change to appropriate sheet

to the appropriate worksheet. Change the line

TopRow = 1 '<<< change to first row number with data

to the first row number that might have data to delete.  This assumes
that when you say "column b = 0" you mean that it has an actual value
of 0, not a default value of 0 as a result of  being empty. This code
will not delete rows in which column B is empty.


Sub AAAA()
    Dim RowNdx As Long
    Dim LastRow As Long
    Dim WS As Worksheet
    Dim TopRow As Long
    
    Set WS = Worksheets("Sheet1") '<<< Change to appropriate sheet
    TopRow = 1 '<<< change to first row number with data
    
    With WS
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        For RowNdx = LastRow To TopRow Step -1
            If Len(.Cells(RowNdx, "B").Text) > 0 Then
                If .Cells(RowNdx, "B").Value = 0 Then
                    .Cells(RowNdx, "A").Resize(, 7).Delete
                End If
            End If
        Next RowNdx
    End With
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
    Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Thu, 1 Jan 2009 14:50:07 -0800, jatman
<jatman@discussions.microsoft.com> wrote:

>i am using the following code to delete the complete row:
>
>        Range("B:B").Select
>            Selection.AutoFilter Field:=1, Criteria1:="0"
>        On Error GoTo line1
>        With Sheet1.Range("b:b")
>        Cells.SpecialCells(xlCellTypeVisible).EntireRow.Delete
>        End With
>line1:
>
>what i need is to delete only columns a:g (not the entire row) if the value 
>in column b = 0.  
>
>any help is appreciated.
>
>jat
0
chip1 (1821)
1/1/2009 11:13:56 PM
Hi,

Here is code to delete all rows which have blank cells in column A.  You can 
modify this to delete all cells of many different types and for any column.

Sub DeleteRows()
    Range("A1:A" & 
Range("A65536").End(xlUp).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub 

Similar code for deleting Columns that all contain formulas which evaluate 
to numbers on row 2 would look like this:

Sub DeleteColumns()
    Range("B2:" & 
[IV2].End(xlToLeft).Address).SpecialCells(xlCellTypeFormulas, 
1).EntireColumn.Delete
End Sub

And the code to address your specific example:

Sub DeleteIfZero()
    With Range("B1:B" & [B65536].End(xlUp).Row)
        Set c = .Find(0, LookIn:=xlValues)
        If Not c Is Nothing Then
            [A:G].Delete
        End If
    End With
End Sub

Note as asked you want to delete the entire columns A:G if any cell in 
column B contains 0.  I'm not sure that my interpretation of your problem is 
correct.

If this helps, please click the Yes button

Cheers,
Shane Devenshire

"jatman" wrote:

> i am using the following code to delete the complete row:
> 
>         Range("B:B").Select
>             Selection.AutoFilter Field:=1, Criteria1:="0"
>         On Error GoTo line1
>         With Sheet1.Range("b:b")
>         Cells.SpecialCells(xlCellTypeVisible).EntireRow.Delete
>         End With
> line1:
> 
> what i need is to delete only columns a:g (not the entire row) if the value 
> in column b = 0.  
> 
> any help is appreciated.
> 
> jat
0
1/3/2009 4:39:01 AM
Reply:

Similar Artilces:

How to Recover Deleted Sent Mail?
While trying to delete very old "Sent" mail I seem to have deleted all "Sent" mail. Is there a way of recovering this mail? Have you closed Outlook since deleting the old sent mail? http://www.howto-outlook.com/howto/restoredeleteditemsfromanoutlookpst.htm might help. Next time, archive the items you want removed from your active .pst file. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, Sidney Friedman as...

Cannot delete subreport
I am using Access 2003 and have a report I did a while back with a simple subreport. I want to remove the subreport but for the life of me can't figure out how to do it. Any help would be greatly appreciated. Thanks. Hi - When you say "remove the sub report", what do you mean? Do you want to delete the entire subreport control containing the subreport, or do you want to keep the control, but change the report contained in it? The first is easy - select the control by clicking once on it once, then press delete. For the second, click the control once, then set ...

Rule for Deleted Items
I am being told that there is a rule in place on my Exchange server that will not empty the deleted items folder every 30 days for certain users in my organization. I found a recipient policy in System Manager that says "Users Excluded from Mailbox Cleanup" but it only shows 2 users and not the 3 I was told about. But I have confirmed that the missing person has email in her deleted items folder going back to 2005 so it must be working. Is there any other location I should be looking? Also, we just had someone come in and migrate our Exchange environment from 2000 to a new...

cannot delete message from deleted items
I have a message in my deleted items folder that when choosing delete opens the McAfee box warning of potential virus and wants me to choose open or do not open, but will not delete. I have tried choosing another file and holding ctrl and choosing the file I want deleted and then choosing delete, I have tried moving it to the desktop but it will only copy there, I have tried every form of delete possible. I need help. Anyone know how? Outlook 2002. Can you empty the deleted items folder entirely? Or turn off the McAfee scanning temporarily to see if it makes a difference? Julie wr...

I can not delete a duplicate personal folders list #2
Vall... amazing that there isn't an easy fix for this. The instructions provided simply don't work ( tools-email accounts-view change email accounts-deliver to new account-finish-close outlook and reopen ), and none of the other offered explanations have worked either. As this is such a common problem; why hasn't microsoft provided a very EASY fix? I am more confused ( and frightened ) and don't want to make the problem worse! Your profile is corrupt, probably based on an incorrect migration of your ..pst file. Create a new mail profile and configure it to use your exi...

Retrieval of Deleted Items After Being Deleted from the Deleted Items File
I deleted a number of important emails from the deleted items file in Outlook 2000. This may sound stupid, but I completely emptied the deleted items file instead of deleting them one by one. Pretty stupid, huh. Anyone. Can they be retrieved? Please help. Thanks. Sorry for sending this again but I seem to be computer illiterate and it has taken me some time to explain the whole situation. Thanks again. unless you use Exchange server with deleted retention enabled, you are most likely out of luck, but you can try something that might help.... http://www.outlook-tips.net/howto/r...

Delete macros
I am using Excel 2002. When I click on Tools->Macro->Macros... i see 2 macros. The problem I am having is that I can't delete these macros, the delete button to the right is grayed out. How can I delete these macros? Hi maybe the macros are protected. Try hitting ALT + F11 to open the VBA editor and try to delete the macros / modules there -- Regards Frank Kabel Frankfurt, Germany excel777 wrote: > I am using Excel 2002. When I click on Tools->Macro->Macros... i see > 2 macros. The problem I am having is that I can't delete these > macros, the delete button to ...

deleting email in outlook, freezes before i can delete
i have a file with pics that symetec scanner says is to large. i can receieve email but cannot send any. it freezes before i can delete and says non responding. Hi All, I want to re-raise the old issue of Fax numbers showing up in the Outlook Address book when one is sending an email. I know that this can be stopped by prepending the Contact's fax number with a letter so that Outlook doesn't see it as a valid fax number and therefore doesn't list it. What's always puzzled me, however, is that this fix doesn't work if the fax numbers are changed using an export to CSV...

Locate a specific row or column
Hi all, Could you tell me how to locate a specific row instead of using Mouse to dray the scroll bar? Clara thank you so much for your help In VBA code, you can use: Range("D100").Activate ' Or Range("D1:D100").Select ' Depending on if you want only one cell highlighted or a range of cells. -- Best wishes, Jim "clara" wrote: > Hi all, > > Could you tell me how to locate a specific row instead of using Mouse to > dray the scroll bar? > > Clara > > thank you so much for your help Hi Clara Have you tried goto in the Ed...

OK to delete Deleted Items folder?
I'm afraid I'll have to delete my Deleted Items folder in Outlook 2000. When I try to empty the folder I get a "The messaging interfce has returned an unknown error. If the problem persists Restart Outlook" message. Is it possible to delete the entire folder and replace it with an empty new one? Will it create any problems? TIA Henrik Not possible. Run scanpst.exe against your pst-file to scan it for errors first. -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Se...

Access/Excel: Create multiple Lines/Column out of one mulit-line Column?
Hallo everyone! I spent a lot of time today searching for a response to my question but I had unfortunately no success. The problem is the following: I have got an Access-table called Employee with an ID and one corresponding Field/Column called comment. These comments are stupidly multi-line (separated by a Return). It's my aim to have access (he he, wordplay) to these two fields in Excel whereas the field shouldn't be longer that 255 characters. I considered three solutions: The table could be changed after being exported to excel in the following two ways: - Multiple Comment Column...

How to delete chart
I created a histogram and want to delete it. I select it and the faint double border apperars. There are no square handles like in 2003. Then I press the Delete key. The faint double border goes away replaced by a single thin black border. The chart is still there and is not able to be selected at all. I entered "delete chart" in the Excel Help window, and there was nothing at all on deleting a chart. Ditto for "remove chart." I got no help searching on the internet either. I have Excel 2007 and Windows XP Professional When the border changes, can you press Delete a...

Delete blank Last page
In a word document where the last page is blank due to editing or whatnot, how do you get rid of the frigg' thing. This is a Visio newsgroup - your question was about Word. However, I have had this problem as you have. Narrowing the margins and line spacing on the page previous to the last may get rid of this annoying "blank" page for you. - Jeff Chapman "silkies" <silkies@discussions.microsoft.com> wrote in message news:BDCC1FF1-50D0-42CE-BA84-868CB26A43AC@microsoft.com... > In a word document where the last page is blank due to editing or > whatnot...

Deleting an email
I have an email (with a file attached) that is "hung up" in my outbox of Microsoft Outlook. Now I can't send or receive emails in Outlook. How can I delete the email that is "hung up"? Define hung up. Is it trying to send it? If so, disconnect your connection while it's trying to send and wait. It will time out after a bit and you should be able to delete it. Reconnect. "Aaron Hurliman" <AaronLHurliman@aol.com> wrote in message news:03b001c34f39$0fb61ff0$a301280a@phx.gbl... > I have an email (with a file attached) that is "hung up&q...

Service section of CRM 3.0
Hello. My question involves working with the Service section of CRM. I am fairly new to the whole CRM system but up to now, going through Sales and Marketing I haven't been to mind-boggled. I am trying to create a new case and link it to a contract through the options that are available by default in the New Case form view. For some reason, when I go to look-up the contract for a particular case I don't return any results. Why??? Basically I'm asking is there any information out there that walks you through the Service section of CRM, else can someone give me a quick ...

Recovering Unrecoverable Deleted Public Folders
Long, sad story with a punch line (which is worth getting to): Exchange 2003. Ran into a situation where a user deleted 10 public folders by mistake. Using Recover Deleted Items to retrieve them, got back five of the folders (the ones that were empty in the first place) but we received the following error message when attempting to recover the other five (the ones with actual stuff in them): "Outlook was unable to recover some or all of the items in this folder. Make sure you have the required permissions to recover items in this folder and try again. If the problem persists contact you...

CRM 4.0 Downloadreports.exe?
I have read a few blogs that discuss this tool in regards to CRM 3.0, however there does not seem to be a CRM 4.0 equilvalent. I want to pull down all reports from CRM into their respective rdl files and copy them to another location. Does anyone have a method of doing this in CRM 4.0? Thanks in advance. On Jun 15, 1:45=A0pm, jimtait <jimtai...@gmail.com> wrote: > I have read a few blogs that discuss this tool in regards to CRM 3.0, > however there does not seem to be a CRM 4.0 equilvalent. > I want to pull down all reports from CRM into their respective rdl > files and cop...

How do i keep the first column of info on my screen?
I have a spreadsheey showing names in column A and then info in columns B onwards. When I scroll I need to see Column A so that I can link the info to the names - how do I get this one column to remain on the screen no matter how far I scroll across? Select B1 and Window>Freeze Panes. If you also want row1 to remain visible select B2 and Window>Freeze Panes. The rule is.......rows above and columns left of the selected cell will be frozen. Gord Dibben Excel MVP On Wed, 30 Nov 2005 11:47:13 -0800, TIQ <TIQ@discussions.microsoft.com> wrote: >I have a spreadsheey showing...

Integration Manager 10.0 error message
Would anyone know the cause if this error? This fixed assets integration ran with no problem last month. "Integration < > is not ready to run due to the following problems: Source queries are not ready to execute. Query < > cannot be executed until the following problem is corrected:" ------ and nothing is listed! Thanks for any help offerred. Are you able to right click on the source and preview? You may have to remap the source file. Thanks, VJ On Nov 3, 10:57=A0am, Patti <Pa...@discussions.microsoft.com> wrote: > Would anyone know the cause if t...

How do I delete a message in my outbox that contains a large file
I tried to send an email containing a large enclosure. Too large to send and now the message is stuck in my outbox. How do I delete the message? I have tried the normal route - cut, delete, but it stays in the outbox and slows down my send/receive capabilities "Lillian" <Lillian@discussions.microsoft.com> wrote in message news:C11E7BA3-C410-48CC-8B15-F6EA284665E7@microsoft.com... > I tried to send an email containing a large enclosure. Too large to send > and > now the message is stuck in my outbox. How do I delete the message? I > have >...

#Deleted
Have a rown in a table that contains the value '#Deleted' in every field. Want to actually delete this row from the table. Tried to delete, it appears that the row is deleted, I exit the table then open the table back up, and the row still exists with the value '#Deleted'. Tried to Compact and Repair.... Still receiveing the same result. How can I remove this row from the table????? The trick is to replace the table with another table populated the *other* records in your bad table. Details: Recovering from corruption: Some table rows show #Deleted at: http:...

Can I recover deleted archived .pst files?
I accidently deleted all of my archived folders, now I need to recover them, is there any way? I had hundreds of e-mails saved that of course I need. Sue State your Outlook version and information store. State how you deleted the files. -- Russ Valentine [MVP-Outlook] "royalpei" <royalpei@discussions.microsoft.com> wrote in message news:B8236C3C-C139-4B03-B2ED-5B135DE9DCC1@microsoft.com... >I accidently deleted all of my archived folders, now I need to recover >them, > is there any way? I had hundreds of e-mails saved that of course I need. > > Sue &q...

How do I combine multiple columns into just 1 column?
In my excel file, the address is split into 4 columns. I want to combine the 4 columns into 1. In a fifth column, use the concanenate function or amphisand to combine the information. Then drag down to copy for each row. =CONCATENATE(A1,B1,C1,D1) or =A1&B1&C1&D1 HTH "scosus" wrote: > In my excel file, the address is split into 4 columns. I want to combine the > 4 columns into 1. ...

MS CRM 4.0 Print Quote to Customer Mail Merge
Trying to print a quote for a customer with multiple line items in the new MS CRM 4.0 using the mail merge. When I start the merge it imports the line items as seperate recipients and creates a new page for each line item. Is there a way set up the merge so that the line items all print on a single page for a quote. I guess I also need to address that if the total number of line items exceed the space allowed on a sinle page then they need to rollover to a new page. Any help would be greatly appreciated. William Hi William I have been struggling with this for a while now and I w...

Can I delete this from ADSI?
Hi all, I am upgrating Exchange 2K to Exchange 2K3 and removed the Mobile information Server (which we never used it). But, I can see the CN=Microsoft-Mobile-Information-Server under configuration -->Services from ADSIedit. Can I safely delete this? or If I do not delete this, wii it have any issue with exchange 2003 mobile? Thanks! Exchange Server 2003 mobility features do not rely on that. Saving a LDIF dump may be a good idea before you delete - this provides ability to recreate the object if required. -- Bharat Suneja MVP - Exchange www.zenprise.com NEW blog location: www.e...