vb for excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keithsimpson3973
    New Member
    • Aug 2006
    • 63

    #1

    vb for excel

    Hi. I am trying build an array in vb applications for excel. I am posting the code for what I am trying to write. Any help would be appreciated greatly..

    Code:
    Sheets("C16-M-001").Select
       Range("A2:H2").Select
       If Range("C2").Value < (Date + 6) And Range("E2").Value < 10 Then
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
         ElseIf Range("C3").Value < (Date + 6) And Range("E3").Value < 100 Then
            Range("A3:H3").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
        ElseIf Range("C4").Value < (Date + 6) And Range("E4").Value < 100 Then
            Range("A4:H4").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
        ElseIf Range("C5").Value < (Date + 6) And Range("E5").Value < 100 Then
            Range("A5:H5").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
        ElseIf Range("C6").Value < (Date + 6) And Range("E6").Value < 100 Then
            Range("A6:H6").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
                 
             ElseIf Range("C7").Value < (Date + 6) And Range("E7").Value < 100 Then
            Range("A7:H7").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
        ElseIf Range("C8").Value < (Date + 6) And Range("E8").Value < 100 Then
            Range("A8:H8").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
        ElseIf Range("C9").Value < (Date + 6) And Range("E9").Value < 100 Then
            Range("A9:H9").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
        ElseIf Range("C10").Value < (Date + 6) And Range("E10").Value < 100 Then
            Range("A10:H10").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
                
        ElseIf Range("C11").Value < (Date + 6) And Range("E11").Value < 100 Then
            Range("A11:H11").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            
        ElseIf Range("C12").Value < (Date + 6) And Range("E12").Value < 100 Then
            Range("A12:H12").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
        ElseIf Range("C13").Value < (Date + 6) And Range("E13").Value < 100 Then
            Range("A13:H13").Select
            Selection.Copy
            Sheets("SCHEDULE").Select
            Range("A8:H8").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    Originally posted by keithsimpson397 3
    Hi. I am trying build an array in vb applications for excel. I am posting the code for what I am trying to write. Any help would be appreciated greatly..
    If you have the code, why do you need help?

    Seriously, you said "I am trying to build an array," but I do not see any array. Also, you post code that we cannot run. What is the problem (what is failing) and what are you trying to do? Thanks! --Sam

    Comment

    • keithsimpson3973
      New Member
      • Aug 2006
      • 63

      #3
      I posted the existing code sent to me.The person was getting the "Procedure to large". I could not post sll of the module here as the size limit won't allow it.

      Comment

      • SammyB
        Recognized Expert Contributor
        • Mar 2007
        • 807

        #4
        Originally posted by keithsimpson397 3
        I posted the existing code sent to me.The person was getting the "Procedure to large". I could not post sll of the module here as the size limit won't allow it.
        Ah, Excel is evil that way. You think that everything works great and add one thing, and you get screwy error messages. What has worked for me is to start over. :D

        It's not that bad. You want to export all of the code modules, classes, and forms. You also want to copy any workbook/worksheet code and paste it into text files. Then delete all of the code that you have exported. Do a SaveAs with your workbook, close it and reopen. When you don't get any enable macros prompts, you know that you have removed all of the code.

        Next, use the Edit, Move or copy sheets menu to create a new workbook from scratch. Again, close down Excel and try to open the new workbook. If it asks if you want to update links, you have a big problem: you'll need to recopy or correct the formulas so as to remove the links.

        Now, you can import the code modules, classes, and forms back into you new workbook. Finally, open the text files and copy/paste the code into the proper worksheet/workbook.

        Finally, you really, really need to write better code. All of those Selects are killing you. You very rarely need to do a Select. For example, your first 8 lines should look something like:
        Code:
        With Sheets("C16-M-001")
        	If .Range("C2").Value < (Date + 6) And .Range("E2").Value < 10 Then
        		.Range("A2:H2").Copy
        		Sheets("SCHEDULE").Range("A8:H8").PasteSpecial Paste:=xlPasteValues, _
        			Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        or even
        Code:
        	With Sheets("C16-M-001")
        		If .Range("C2").Value < (Date + 6) And .Range("E2").Value < 10 Then _
        			Sheets("SCHEDULE").Range("A8:H8").Value = .Range("A2:H2").Value
        	End With
        Also at the top of each module/class/form you should have Option Explicit which will make sure that you have properly defined all of your variables. Hope this helps a little. Depending on the amount of code, you have a large job to do.

        Comment

        • keithsimpson3973
          New Member
          • Aug 2006
          • 63

          #5
          Thanks SammyB. The person doing the project is getting ready to rework it, but isn't a real exp programmer. It was originally written by her supervisor who simply recorded macros then pasted the code into modules, then copy and pastes over and over and over, you get the point. I will pass on the info to the person in nedd, and thanks again for the tips!

          Comment

          Working...