Solved

Amend Code

Posted on 2013-11-21
2
189 Views
Last Modified: 2013-11-22
Hi,

I have a sub below that deals with sheets calculation D1 & D2 &d3 before it deals with  calculation variance d2 & d3

Can someone amend so it deals with calculation variance d2 & d3 first and then the rest

Many thanks
Seamus

--------------------







Sub PrepTool()

' Macro expands sheet for use with required number of records
' Be aware that many aspects of this macro are hard coded (e.g. the lengths of the lines to be copied down)
' and, as such, can be easily broken if the tool is amended


Dim Records As Long
Dim Selection As Integer
Dim x As Integer ' counter

On Error GoTo Finish

Selection = MsgBox("You are about to be asked how many records you will need in the tool. Be aware that choosing a large number of records will inflate the size of the tool markedly. You should save a new version of the tool before choosing to expand for your records as this cannot be undone.  Choose 'Cancel' to go back and save", vbOKCancel)

If Selection = vbCancel Then Exit Sub

Records = InputBox("How many records are you planning to input?", "Sample", 2)

Application.ScreenUpdating = False


'Turns off auto-calculate
Application.Calculation = xlCalculationManual


For x = 1 To 2

    With Sheets("Input - D" & x)
        .Activate
        .Unprotect
    End With
        Range("B8:DW8").AutoFill Range("B8:DW" & (Records + 7))
    ActiveSheet.Protect
    With Sheets("Calculation - D" & x)
        .Activate
        .Unprotect
    End With
        Range("A14:BJ14").AutoFill Range("A14:BJ" & (Records + 13))
    ActiveSheet.Protect

Next x

    With Sheets("Calculation - variation - D2")
        .Activate
        .Unprotect
    End With
        Range("A12:FE12").AutoFill Range("A12:FE" & (Records + 11))
    ActiveSheet.Protect

    With Sheets("Input - D3")
        .Activate
        .Unprotect
    End With
        Range("B8:DW8").AutoFill Range("B8:DW107")
    ActiveSheet.Protect
   
    With Sheets("Calculation - D3")
        .Activate
        .Unprotect
    End With
        Range("A14:BJ14").AutoFill Range("A14:BJ113")
    ActiveSheet.Protect
   
    With Sheets("Calculation - variation - D3")
        .Activate
        .Unprotect
    End With
        Range("A12:FE12").AutoFill Range("A12:FE111")
    ActiveSheet.Protect


Finish:

Sheets("Instructions for use").Activate

Application.ScreenUpdating = True

MsgBox "Your Tool is now ready for use", vbOKOnly, "Ready"

End Sub
0
Comment
Question by:Seamus2626
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39666942
Try this

Sub PrepTool()

' Macro expands sheet for use with required number of records
' Be aware that many aspects of this macro are hard coded (e.g. the lengths of the lines to be copied down)
' and, as such, can be easily broken if the tool is amended


Dim Records As Long
Dim Selection As Integer
Dim x As Integer ' counter

On Error GoTo Finish

Selection = MsgBox("You are about to be asked how many records you will need in the tool. Be aware that choosing a large number of records will inflate the size of the tool markedly. You should save a new version of the tool before choosing to expand for your records as this cannot be undone.  Choose 'Cancel' to go back and save", vbOKCancel)

If Selection = vbCancel Then Exit Sub

Records = InputBox("How many records are you planning to input?", "Sample", 2)

Application.ScreenUpdating = False


'Turns off auto-calculate
Application.Calculation = xlCalculationManual

    With Sheets("Calculation - variation - D2")
        .Activate
        .Unprotect
    End With
        Range("A12:FE12").AutoFill Range("A12:FE" & (Records + 11))
    ActiveSheet.Protect

    With Sheets("Calculation - variation - D3")
        .Activate
        .Unprotect
    End With
        Range("A12:FE12").AutoFill Range("A12:FE111")
    ActiveSheet.Protect

For x = 1 To 2

    With Sheets("Input - D" & x)
        .Activate
        .Unprotect
    End With
        Range("B8:DW8").AutoFill Range("B8:DW" & (Records + 7))
    ActiveSheet.Protect
    With Sheets("Calculation - D" & x)
        .Activate
        .Unprotect
    End With
        Range("A14:BJ14").AutoFill Range("A14:BJ" & (Records + 13))
    ActiveSheet.Protect

Next x

    With Sheets("Input - D3")
        .Activate
        .Unprotect
    End With
        Range("B8:DW8").AutoFill Range("B8:DW107")
    ActiveSheet.Protect
   
    With Sheets("Calculation - D3")
        .Activate
        .Unprotect
    End With
        Range("A14:BJ14").AutoFill Range("A14:BJ113")
    ActiveSheet.Protect
   


Finish:

Sheets("Instructions for use").Activate

Application.ScreenUpdating = True

MsgBox "Your Tool is now ready for use", vbOKOnly, "Ready"

End Sub

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 39668334
Thanks ssaqibh!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now