Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with VBA Case for Excel 1

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
523
US
So here is the problem. I would like to run a case function and haven't seen an example on how to do it. First off I am generating a series of numbers and printing them out in excel. I them and copying that printout and duplicationg it after its printout (probably a better way to do this than what I have). I would like to keep addin onto the list until a specific amount of times of duplication. Here is what I have tried:

occurances = the total amount of values to be copied (minus the header)
NX1Count = Total amount of of reproductions (starting at 1)

What is occuring is that the first Case is not met (should not be met), and it goes to the second case, but it is not entering the case. What can I change the second case to that will cause the case to be active from 2< a possible infinite number?

Thanks,


Code:
Range("B2").Select
Range("B2", ActiveCell.Offset(Occurances - 1, 0)).Copy

Cells(Occurances + 2, 2).Select
ActiveSheet.Paste


NX1Count = NX1Count + 1

Do While NX1Count <= (Occurances)

    Select Case NX1Count
    
        Case 1
        Cells((NX1Count * (Occurances + 2)), 2).Select
        ActiveSheet.Paste
        
        Case (NX1Count > 1)
        Cells((NX1Count * (Occurances)), 2).Select
        ActiveSheet.Paste
        
    End Select

Loop
 
Replace "Case (NX1Count > 1)" with "Case Is > 1" or "Case Else".
 
Thanks,

I did some more math and was able to create a statement without the case that worked instead. This was after I located your solution. Thank you again! You get a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top