PC Review


Reply
Thread Tools Rate Thread

Delete and Shift Cells up

 
 
matt
Guest
Posts: n/a
 
      16th Jul 2008
Hi all,
I'm trying to create a macro that will start at the very first cell, I guess
A1, and work it's way down, and will check the value of the cell. If the
value of the cell is not equal to the word "Sales" then delete that row. but
if it finds the word sales then stop the process.
Also can I have this macro be able to autorun on the save of the doc? For
instance if I save an email attchment that is an excel file will it run when
I save the attachment without opening the file and then saving it? So to be a
little more clear if I right-click on the excel attached file in the email
and click save, can i have this macro run?
 
Reply With Quote
 
 
 
 
Bernard Liengme
Guest
Posts: n/a
 
      16th Jul 2008
I think a big No to part 2. When you 'save' an email attachment you are
really just copying a file from a temp to a permanent folder so Excel does
not know anything is happening to the file
You could have the macro run when the file is opened with an 'open even'
Private Sub Workbook_Open()
run the code
End Sub
This code must go on the workBOOK module - right click the Excel log next to
'File' on the menu and use View code

Do you have a question about coding the macro?
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"matt" <(E-Mail Removed)> wrote in message
news:C70F0B59-3D17-48F7-883E-(E-Mail Removed)...
> Hi all,
> I'm trying to create a macro that will start at the very first cell, I
> guess
> A1, and work it's way down, and will check the value of the cell. If the
> value of the cell is not equal to the word "Sales" then delete that row.
> but
> if it finds the word sales then stop the process.
> Also can I have this macro be able to autorun on the save of the doc? For
> instance if I save an email attchment that is an excel file will it run
> when
> I save the attachment without opening the file and then saving it? So to
> be a
> little more clear if I right-click on the excel attached file in the email
> and click save, can i have this macro run?



 
Reply With Quote
 
matt
Guest
Posts: n/a
 
      16th Jul 2008
Wow, thanks for your QUICK response. Yes would you be able to help me code
this. So it is like this, Start in cell A1 and go down(just column A is fine)
search for the value in the cell to be <> "Sales" Then delete row and shift
up the rows. But If the value = "Sales" then break out of the loop.
Thanks,

"Bernard Liengme" wrote:

> I think a big No to part 2. When you 'save' an email attachment you are
> really just copying a file from a temp to a permanent folder so Excel does
> not know anything is happening to the file
> You could have the macro run when the file is opened with an 'open even'
> Private Sub Workbook_Open()
> run the code
> End Sub
> This code must go on the workBOOK module - right click the Excel log next to
> 'File' on the menu and use View code
>
> Do you have a question about coding the macro?
> best wishes
> --
> Bernard V Liengme
> Microsoft Excel MVP
> http://people.stfx.ca/bliengme
> remove caps from email
>
> "matt" <(E-Mail Removed)> wrote in message
> news:C70F0B59-3D17-48F7-883E-(E-Mail Removed)...
> > Hi all,
> > I'm trying to create a macro that will start at the very first cell, I
> > guess
> > A1, and work it's way down, and will check the value of the cell. If the
> > value of the cell is not equal to the word "Sales" then delete that row.
> > but
> > if it finds the word sales then stop the process.
> > Also can I have this macro be able to autorun on the save of the doc? For
> > instance if I save an email attchment that is an excel file will it run
> > when
> > I save the attachment without opening the file and then saving it? So to
> > be a
> > little more clear if I right-click on the excel attached file in the email
> > and click save, can i have this macro run?

>
>
>

 
Reply With Quote
 
Bernard Liengme
Guest
Posts: n/a
 
      16th Jul 2008
This worked for me

Sub Exterminator()
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
mycount = Selection.Count
For j = mycount To 1 Step -1
If Cells(j, 1).Value = "Sales" Then
Exit Sub
Else
Rows(j).Select
Selection.Delete Shift:=xlUp
End If
Next j
End Sub


But in VBA the entry "sales" is not equal to "Sales
To stop at any entry with those letters; replace
If Cells(j, 1).Value = "Sales" Then
with
If Ucase(Cells(j, 1).Value) = "SALES" Then

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"matt" <(E-Mail Removed)> wrote in message
news:63903445-2672-4E81-84AE-(E-Mail Removed)...
> Wow, thanks for your QUICK response. Yes would you be able to help me code
> this. So it is like this, Start in cell A1 and go down(just column A is
> fine)
> search for the value in the cell to be <> "Sales" Then delete row and
> shift
> up the rows. But If the value = "Sales" then break out of the loop.
> Thanks,
>
> "Bernard Liengme" wrote:
>
>> I think a big No to part 2. When you 'save' an email attachment you are
>> really just copying a file from a temp to a permanent folder so Excel
>> does
>> not know anything is happening to the file
>> You could have the macro run when the file is opened with an 'open even'
>> Private Sub Workbook_Open()
>> run the code
>> End Sub
>> This code must go on the workBOOK module - right click the Excel log next
>> to
>> 'File' on the menu and use View code
>>
>> Do you have a question about coding the macro?
>> best wishes
>> --
>> Bernard V Liengme
>> Microsoft Excel MVP
>> http://people.stfx.ca/bliengme
>> remove caps from email
>>
>> "matt" <(E-Mail Removed)> wrote in message
>> news:C70F0B59-3D17-48F7-883E-(E-Mail Removed)...
>> > Hi all,
>> > I'm trying to create a macro that will start at the very first cell, I
>> > guess
>> > A1, and work it's way down, and will check the value of the cell. If
>> > the
>> > value of the cell is not equal to the word "Sales" then delete that
>> > row.
>> > but
>> > if it finds the word sales then stop the process.
>> > Also can I have this macro be able to autorun on the save of the doc?
>> > For
>> > instance if I save an email attchment that is an excel file will it run
>> > when
>> > I save the attachment without opening the file and then saving it? So
>> > to
>> > be a
>> > little more clear if I right-click on the excel attached file in the
>> > email
>> > and click save, can i have this macro run?

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete all the blanc cells in a worksheet and shift cells l =?Utf-8?B?dGlyYW1pc3U=?= Microsoft Excel Misc 2 7th Dec 2006 03:45 AM
Delete cells with text, and shift cells left? Ryk Microsoft Excel Discussion 1 10th Nov 2006 06:40 AM
Delete cells with text and shift left? Ryk Microsoft Access Macros 1 10th Nov 2006 03:03 AM
Delete - Shift Cells UP problem =?Utf-8?B?UmFscGg=?= Microsoft Excel Misc 3 22nd Mar 2005 11:19 PM
How do I change the default 'shift cells up' when I delete a rang. =?Utf-8?B?YWxpbmVqb2huc29u?= Microsoft Excel Setup 0 17th Nov 2004 09:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:56 PM.