MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 6th, 2002, 12:39 PM   #1
Mood
New Member
 
Join Date: Mar 2002
Location: Manitoba, Canada
Posts: 22
Default

I have searched the board without any luck. I’ve come close, but no cigars.

I have a question about whether I can automatically delete certain cells all in the same row, but not in adjacent columns. All based on an answer from a popup box, or something similar??


First, I would like to press a button to start the macro,

Then ask the user for the id #, or cancel the macro,

Find the row with the id# in column E, (the sheet has up to 355 rows and is dynamic),

Then go to the left of the id# cell (same row) and start to delete the cell in column D (has a checkmark, formatted as Marlett font),

Then delete cell in column E (id#),

Delete cells in Columns F and G (front and back names),

Skip the cell in column H (formulas),

Then delete the next two cells in columns I and J (both dates),

Skip the last two columns K and L, (the deleting basically ends in column J),

Then a message box pops up either confirming the deletions, or if the user canceled.


Hope I’ve made myself clear, and much thanks for all the fantastic help on this board.

Peter
Mood is offline   Reply With Quote
Old May 6th, 2002, 01:22 PM   #2
klb
Board Regular
 
Join Date: Apr 2002
Location: Minnesota
Posts: 821
Default

quick question -

Do you mean "delete the cells" or "delete the contents of the cells"?

Deleting cells will cause adjacent cells to shift.

Deleting the contents leaves the structure of your workbook intact.
klb is offline   Reply With Quote
Old May 6th, 2002, 01:27 PM   #3
Mood
New Member
 
Join Date: Mar 2002
Location: Manitoba, Canada
Posts: 22
Default

Quote:
On 2002-05-06 12:22, klb wrote:
quick question -

Do you mean "delete the cells" or "delete the contents of the cells"?

Deleting cells will cause adjacent cells to shift.

Deleting the contents leaves the structure of your workbook intact.
"Deleting the contents" would be correct. I would like the structure preserved for future use.

Peter
Mood is offline   Reply With Quote
Old May 6th, 2002, 01:33 PM   #4
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Probably something along these lines:

Code:
Sub deller()
Dim myid As Integer, mrw2 As Long, mycl As Range
On Error GoTo 1
myid = Application.InputBox("Enter your id #", Type:=1)
Set mycl = Columns("e").Find(What:=myid)
mrw2 = mycl.Row
Range("d" & mrw2 & ":g" & mrw2).ClearContents
Range("i" & mrw2 & ":j" & mrw2).ClearContents
MsgBox "Delete Confirmation"
Exit Sub
1: MsgBox "Action Cancelled or ID not Found"
End Sub
_________________
Cheers, NateO

[ This Message was edited by: nateo on 2002-05-06 12:54 ]
NateO is offline   Reply With Quote
Old May 6th, 2002, 02:20 PM   #5
Mood
New Member
 
Join Date: Mar 2002
Location: Manitoba, Canada
Posts: 22
Default

Quote:
On 2002-05-06 12:33, NateO wrote:
Probably something along these lines:

Code:
Sub deller()
Dim myid As Integer, mrw2 As Long, mycl As Range
On Error GoTo 1
myid = Application.InputBox("Enter your id #", Type:=1)
Set mycl = Columns("e").Find(What:=myid)
mrw2 = mycl.Row
Range("d" & mrw2 & ":g" & mrw2).ClearContents
Range("i" & mrw2 & ":j" & mrw2).ClearContents
MsgBox "Delete Confirmation"
Exit Sub
1: MsgBox "Action Cancelled or ID not Found"
End Sub
_________________
Cheers, NateO

[ This Message was edited by: nateo on 2002-05-06 12:54 ]
Boy, did that do the trick. Thank you very much... Coffee's on me.

PS.
I'm trying to figure it all out, but I don't quite understand it. Maybe time or experience will help.

Much gratitude, Peter
Mood is offline   Reply With Quote
Old May 6th, 2002, 04:43 PM   #6
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Peter, you're welcome. Coffee sounds great, and being in Minneapolis, I'm not too far off. It may help if I include notes, I added them in the code below (note is above pertinent line). Also, in previous code, I did two deletes, one for d:g, and one for i:j. In the code below, I delete both sections [via union] in one procedural line of code.

Code:
Sub deller2()
Dim myid As Integer, mrw2 As Long, mycl As Range
'error trapper used latter, 1 is line identifier
On Error GoTo 1
'inputbox with validation, input must be numeric
myid = Application.InputBox("Enter your id #", Type:=1)
'look in column E for 'myid' and set this as range
'if user cancels, or XL can't find it, line above will cause an error and Xl goes to 1:
Set mycl = Columns("e").Find(What:=myid)
'grab the row number of the found cell
mrw2 = mycl.Row
'clear two sections
Union(Range("d" & mrw2 & ":g" & mrw2), _
Range("i" & mrw2 & ":j" & mrw2)).ClearContents
MsgBox "Delete Confirmation" 'made it this far w/ no errors, tell end-user
Exit Sub 'exit sub so not to show message below
1: MsgBox "Action Cancelled or ID not Found" ' 'mycel' could not be set, here's the error
End Sub
Hope this helps.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-06 15:46 ]
NateO is offline   Reply With Quote
Old May 7th, 2002, 07:01 AM   #7
Mood
New Member
 
Join Date: Mar 2002
Location: Manitoba, Canada
Posts: 22
Default

Quote:

Code:
myid = Application.InputBox("Enter your id #", Type:=1)

'if user cancels, or XL can't find it, line above will cause an error and Xl goes to 1:
Set mycl = Columns("e").Find(What:=myid)


End Sub
Hope this helps.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-06 15:46 ]
Hi Nate

Sorry for the delay in responding, but my job seems to be getting between me and XL.

I've encountered a slight problem when I press the cancel button. The macro will go and delete a row and then confirm the deletion. It doesn't cancel the macro.

I tried to place this line of code after myid:

myid = Application.InputBox...
If CStr(myid) = "False" Then Exit Sub

to try and cancel the dialog box. No luck. I seem to be stumped, again.

Off to bed I go, and thanks
Peter


Mood is offline   Reply With Quote
Old May 7th, 2002, 07:12 AM   #8
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Maybe change:

If CStr(myid) = "False" Then Exit Sub

to:

If myid = 0 Then Exit Sub

Tom



Tom Schreiner is offline   Reply With Quote
Old May 7th, 2002, 09:52 AM   #9
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Try the following (Much like Tom Stated):

Code:
Sub deller2()
Dim myid As Integer, mrw2 As Long, mycl As Range
'error trapper used latter, 1 is line identifier
'On Error GoTo 1
'inputbox with validation, input must be numeric
myid = Application.InputBox("Enter your id #", Type:=1)
If myid = Empty Then
MsgBox "Action Cancelled"
Exit Sub
End If
'look in column E for 'myid' and set this as range
'if user cancels, or XL can't find it, line above will cause an error and Xl goes to 1:
Set mycl = Columns("e").Find(What:=myid)
'grab the row number of the found cell
mrw2 = mycl.Row
'clear two sections
Union(Range("d" & mrw2 & ":g" & mrw2), _
Range("i" & mrw2 & ":j" & mrw2)).ClearContents
MsgBox "Delete Confirmation" 'made it this far w/ no errors, tell end-user
Exit Sub 'exit sub so not to show message below
1: MsgBox "ID not Found" ' 'mycel' could not be set, here's the error
End Sub
I was overly focused on the range test as cancellation, but we can use the inputbox as well.

Hope this helps.
___________________________________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-05-07 09:28 ]
NateO is offline   Reply With Quote
Old May 7th, 2002, 02:35 PM   #10
Mood
New Member
 
Join Date: Mar 2002
Location: Manitoba, Canada
Posts: 22
Default

Thanks to both TsTom and NateO. Both of the ideas were a complete success.

I'm one happy coffee drinker. I'll be buying the next round.

Peter
Mood is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On

Forum Jump


All times are GMT -4. The time now is 05:31 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes