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 1st, 2002, 06:11 PM   #1
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

Ok, I will try this way. I am in a For i loop. I want to test the value of Cell AP10 and if it is blank, I want skip over a bunch of code and go to the next i instruction to restart the loop. I cant figgure out how to do it. I tried a Select Case but that gives me a compile error at the next i instruction. HELP
elgringo56 is offline   Reply With Quote
Old May 1st, 2002, 06:19 PM   #2
RET79
Board Regular
 
Join Date: Mar 2002
Location: England, UK.
Posts: 526
Default

a really rough quick guess but you need something alone the lines of

For i = 1 to n

If Isempty("AP10") = false then
'do code

End if
Next i

[ This Message was edited by: RET79 on 2002-05-01 18:16 ]
RET79 is offline   Reply With Quote
Old May 1st, 2002, 06:49 PM   #3
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

When I try this, I get a compile error on the Next i statment saying I have a next without a for
elgringo56 is offline   Reply With Quote
Old May 1st, 2002, 06:53 PM   #4
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

This is my code, and it doesn't work
For i = 1 To LoopRange
Range("AA6").Select
Selection.Copy
Range("AB6").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("AA9").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("AB5:AB6"), CopyToRange:=Range("AP9:BB9"), Unique:=False
If IsEmpty("AP10") = False Then
Range("BE10:BE61").Select
Selection.Copy
Range("BB10:BB61").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("AP9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
Range("AP9").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
Range("AP10").Select
ActiveCell.CurrentRegion.Select
Selection.Copy
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("AP10:BB509").Select
Selection.ClearContents
Next i
elgringo56 is offline   Reply With Quote
Old May 1st, 2002, 06:57 PM   #5
RET79
Board Regular
 
Join Date: Mar 2002
Location: England, UK.
Posts: 526
Default

Try putting an End IF just before Next i.

Sorry i have to go to bed now I'm sure others will help you if that doesn't work

RET79
RET79 is offline   Reply With Quote
Old May 1st, 2002, 07:07 PM   #6
RET79
Board Regular
 
Join Date: Mar 2002
Location: England, UK.
Posts: 526
Default

Or Try this:

For i = 1 To LoopRange

' code

If [AP10] <> "" Then

'code
End if
Next i


Not certain if that will work as u want but worth a try, get yourself a VBA book and learn how to edit your code so it has less select selection stuff as its difficult to debug and understand. The macro recorder is great for learning how to do stuff but it doesnt leave you with the best code to work with and understand. Good luck

RET79

[ This Message was edited by: RET79 on 2002-05-01 18:15 ]
RET79 is offline   Reply With Quote
Old May 1st, 2002, 07:24 PM   #7
RET79
Board Regular
 
Join Date: Mar 2002
Location: England, UK.
Posts: 526
Default

For i = 1 To LoopRange

Range("AA6").Copy
Range("AB6").PasteSpecial Paste:=xlValues
Range([AA9], [AA9].End(xlDown).End(xltoRight).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
Range("AB5:AB6"), CopyToRange:=Range("AP9:BB9"), Unique:=False

If [AP10] <> "" Then

Range("BE10:BE61").Copy
Range("BB10:BB61").PasteSpecial Paste:=xlValues
Range("AP9").End(xlDown).Offset(1, 0).Select
Range(Selection, Selection.End(xlToRight)).ClearContents
Range([Ap9], [AP9].End(xlToRight)).ClearContents
Range("AP10").CurrentRegion.Copy
Range("A1").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlValues
Range("AP10:BB509").ClearContents

End if
Next i



I tidied up your code a bit, should probably run quicker even.

RET79

[ This Message was edited by: RET79 on 2002-05-01 18:31 ]
RET79 is offline   Reply With Quote
Old May 1st, 2002, 07:29 PM   #8
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi,

I cannot follow what you are doing, but here is some of your code rewritten to remove as many .select statements that I can without knowing your data layout.

Code:
Sub test()
Dim LoopRange, i
LoopRange = 4

For i = 1 To LoopRange
    Range("AA6").Copy
    Range("AB6").PasteSpecial (xlValues)
    
    Range("AA9").Select
    Range(Selection, Selection.End(xlDown)).Select
    
    Range(Selection, Selection.End(xlToRight)).AdvancedFilter _
    Action:=xlFilterCopy, CriteriaRange:= _
    Range("AB5:AB6"), CopyToRange:=Range("AP9:BB9"), Unique:=False
    
    If IsEmpty("AP10") = False Then
        Range("BE10:BE61").Copy
        Range("BB10:BB61").PasteSpecial (xlValues)
        
        Range("AP9").End(xlDown).Offset(1, 0).Select
        Range(Selection, Selection.End(xlToRight)).ClearContents
        
        Range("AP9").Select
        Range(Selection, Selection.End(xlToRight)).ClearContents
        
        Range("AP10").CurrentRegion.Copy
        Range("A1").End(xlDown).Offset(1, 0).PasteSpecial (xlValues)
        Range("AP10:BB509").ClearContents
    End If

Next i

End Sub
Please report back what you wish to do and where the problems remain.

Jay

EDIT: The following code removes all the select statements. Don't know if it would work, though.

Code:
Sub tester()
Dim LoopRange, i
Dim Rng1 As Range, Rng2 As Range, Rng3 As Range

LoopRange = 4

For i = 1 To LoopRange
    Range("AB6") = Range("AA6")
    
    Set Rng1 = Range("AA9", Range("AA9").End(xlDown))
    Set Rng2 = Range(Rng1, Rng1.End(xlToRight))
    
    Rng2.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:= _
    Range("AB5:AB6"), CopyToRange:=Range("AP9:BB9"), Unique:=False
    
    If IsEmpty("AP10") = False Then
        Range("BE10:BE61").Copy
        Range("BB10:BB61").PasteSpecial (xlValues)
        
        Set Rng3 = Range("AP9", Range("AP9").End(xlDown).Offset(1, 0))
        Range(Rng3, Rng3.End(xlToRight)).ClearContents
               
        Range("AP10").CurrentRegion.Copy
        Range("A1").End(xlDown).Offset(1, 0).PasteSpecial (xlValues)
        Range("AP10:BB509").ClearContents
    End If

Next i

End Sub
[ This Message was edited by: Jay Petrulis on 2002-05-01 18:54 ]
Jay Petrulis is offline   Reply With Quote
Old May 1st, 2002, 07:34 PM   #9
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

That got it, thanks millions
elgringo56 is offline   Reply With Quote
Old May 1st, 2002, 07:39 PM   #10
elgringo56
Board Regular
 
Join Date: Apr 2002
Location: Puerto Vallarta, Mexico
Posts: 869
Default

Jay. Thanks heaps, I will study your code. some of the selects and clears I was doing were to totally clear some cells that were produced by other formulas and therefore not blank even though they appeared blank. the paste value only does not leave a cell blank if the blank that is in the cell was developed by a formula, this has been a real headache for me for a long time.
elgringo56 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 07:22 AM.


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