+ Reply to Thread
Results 1 to 3 of 3

Changing static code to dynamic code

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2013
    Location
    Cranfield
    MS-Off Ver
    Excel 2007
    Posts
    68

    Changing static code to dynamic code

    Hi All,

    I have some code here that I can't figure out.

    The first code selcts 3 rows, inserts some more and then copies up the same format and clears certain areas. It does this for specific rows i.e. 31:33

    The second code does the same but for only one row. This code however, is dynamic so when the rows change, it can follow down and insert the row inthe right place.

    I need to combine these to so that I can select 3 rows and copy and paste and stuff but be dynamic to get it in the right place.

    Any suggestions?

    Sub New_Notice()
    '
    ' New Notice Macro
        Rows("31:33").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
        Rows("34:36").Select
        Selection.AutoFill Destination:=Rows("31:36"), Type:=xlFillDefault
        Rows("31:36").Select
        Range("B31:B33, C31, D31:K33").Select
        Selection.ClearContents
        Range("B31").Select
    End Sub
    Sub New_DATA()
    '
    ' New DATA Macro
        Dim rowPosition As Integer
    With Worksheets("MASTER")
            rowPosition = .Cells(1, 4).Value
            .Rows(rowPosition).EntireRow.Select
                Selection.Insert Shift:=x1Down, CopyOrigin:=xlFormatFromRightOrBelow
                Rows(rowPosition + 1).Select
                Selection.AutoFill Destination:=.Range(.Cells(rowPosition, 1), .Cells(rowPosition + 1, 1)).EntireRow, Type:=xlFillDefault
                .Range(.Cells(rowPosition, 2), .Cells(rowPosition, 11)).ClearContents
            .Cells(rowPosition, 2).Select
        End With
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Changing static code to dynamic code

    You can select multiple rows like this:
    .Rows(rowPosition & ":" & rowPosition + 2).EntireRow.Select

  3. #3
    Registered User
    Join Date
    04-30-2013
    Location
    Cranfield
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: Changing static code to dynamic code

    Thank you so much.
    I was puttring the quotation marks in the wrong place!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1