Formatting Cells within a Selection Loop












2















I have a loop macro that changes a row of dates based on cells I have selected. Is there an easy way to format these cells without complicating the code. My company has policies around keeping Macros as simple as possible.



I have tried the below at the top of the code but this formats the whole sheet, not the relevant cells.



cells.HorizontalAlignment = xlRight
cells.NumberFormat = "mmm-yy"


I can do it via the below but it adds 100 lines to the code



cell.Offset(0, 0) = "1-Jul-19"
cell.Offset(0, 0).HorizontalAlignment = xlRight
cell.Offset(0, 0).NumberFormat = "mmm-yy"


Is there a way to do this on one line i.e.



cell.Offset(0, 0) = "1-Jul-19".HorizontalAlignment = xlRight.NumberFormat = "mmm-yy"


Help would be much appreciated.



Scott





**Sub CHANGE_MONTH_LOOP()
Dim rngMyRange As range
Dim cell As range
Set rngMyRange = Selection
For Each cell In rngMyRange.Cells
cell.Offset(0, 0) = "1-Jul-19"

cell.Offset(0, 1) = "1-Aug-19"

cell.Offset(0, 2) = "1-Sep-19"

Next cell

End Sub**









share|improve this question























  • Woops, didn't notice the date part. Below will do the formatting and alignment. With the date, what are you doing with it? Is it just for a year? Why not hard codee if it is?

    – alowflyingpig
    Nov 14 '18 at 1:55











  • I have 750 worksheets that contain around 15,000 rows for a budgeting system. Last years Budgets go from July-2018 across to June-2020 (27 cells) I need to change these 27 cells in all relevant lines to July-2019 to June-2021. What I am trying to do is format only the cells I have modified to make sure they are in the "mmm-yy" format and right aligned. It stuffs up the readability of the sheet if everything is right aligned. In terms of your code wont that format the entire sheet in that format? (which is what I am trying to avoid).

    – Scottyp
    Nov 14 '18 at 2:10











  • no, it only formats row 1 in worksheet Sheet1. As I understand you want to loop through ALL worksheets within the workbook and make sure the format of row1 is "mmm-yy"?

    – alowflyingpig
    Nov 14 '18 at 2:33











  • If the below answer does what you want it to can you please ensure you mark as correct.

    – alowflyingpig
    Nov 14 '18 at 3:01
















2















I have a loop macro that changes a row of dates based on cells I have selected. Is there an easy way to format these cells without complicating the code. My company has policies around keeping Macros as simple as possible.



I have tried the below at the top of the code but this formats the whole sheet, not the relevant cells.



cells.HorizontalAlignment = xlRight
cells.NumberFormat = "mmm-yy"


I can do it via the below but it adds 100 lines to the code



cell.Offset(0, 0) = "1-Jul-19"
cell.Offset(0, 0).HorizontalAlignment = xlRight
cell.Offset(0, 0).NumberFormat = "mmm-yy"


Is there a way to do this on one line i.e.



cell.Offset(0, 0) = "1-Jul-19".HorizontalAlignment = xlRight.NumberFormat = "mmm-yy"


Help would be much appreciated.



Scott





**Sub CHANGE_MONTH_LOOP()
Dim rngMyRange As range
Dim cell As range
Set rngMyRange = Selection
For Each cell In rngMyRange.Cells
cell.Offset(0, 0) = "1-Jul-19"

cell.Offset(0, 1) = "1-Aug-19"

cell.Offset(0, 2) = "1-Sep-19"

Next cell

End Sub**









share|improve this question























  • Woops, didn't notice the date part. Below will do the formatting and alignment. With the date, what are you doing with it? Is it just for a year? Why not hard codee if it is?

    – alowflyingpig
    Nov 14 '18 at 1:55











  • I have 750 worksheets that contain around 15,000 rows for a budgeting system. Last years Budgets go from July-2018 across to June-2020 (27 cells) I need to change these 27 cells in all relevant lines to July-2019 to June-2021. What I am trying to do is format only the cells I have modified to make sure they are in the "mmm-yy" format and right aligned. It stuffs up the readability of the sheet if everything is right aligned. In terms of your code wont that format the entire sheet in that format? (which is what I am trying to avoid).

    – Scottyp
    Nov 14 '18 at 2:10











  • no, it only formats row 1 in worksheet Sheet1. As I understand you want to loop through ALL worksheets within the workbook and make sure the format of row1 is "mmm-yy"?

    – alowflyingpig
    Nov 14 '18 at 2:33











  • If the below answer does what you want it to can you please ensure you mark as correct.

    – alowflyingpig
    Nov 14 '18 at 3:01














2












2








2








I have a loop macro that changes a row of dates based on cells I have selected. Is there an easy way to format these cells without complicating the code. My company has policies around keeping Macros as simple as possible.



I have tried the below at the top of the code but this formats the whole sheet, not the relevant cells.



cells.HorizontalAlignment = xlRight
cells.NumberFormat = "mmm-yy"


I can do it via the below but it adds 100 lines to the code



cell.Offset(0, 0) = "1-Jul-19"
cell.Offset(0, 0).HorizontalAlignment = xlRight
cell.Offset(0, 0).NumberFormat = "mmm-yy"


Is there a way to do this on one line i.e.



cell.Offset(0, 0) = "1-Jul-19".HorizontalAlignment = xlRight.NumberFormat = "mmm-yy"


Help would be much appreciated.



Scott





**Sub CHANGE_MONTH_LOOP()
Dim rngMyRange As range
Dim cell As range
Set rngMyRange = Selection
For Each cell In rngMyRange.Cells
cell.Offset(0, 0) = "1-Jul-19"

cell.Offset(0, 1) = "1-Aug-19"

cell.Offset(0, 2) = "1-Sep-19"

Next cell

End Sub**









share|improve this question














I have a loop macro that changes a row of dates based on cells I have selected. Is there an easy way to format these cells without complicating the code. My company has policies around keeping Macros as simple as possible.



I have tried the below at the top of the code but this formats the whole sheet, not the relevant cells.



cells.HorizontalAlignment = xlRight
cells.NumberFormat = "mmm-yy"


I can do it via the below but it adds 100 lines to the code



cell.Offset(0, 0) = "1-Jul-19"
cell.Offset(0, 0).HorizontalAlignment = xlRight
cell.Offset(0, 0).NumberFormat = "mmm-yy"


Is there a way to do this on one line i.e.



cell.Offset(0, 0) = "1-Jul-19".HorizontalAlignment = xlRight.NumberFormat = "mmm-yy"


Help would be much appreciated.



Scott





**Sub CHANGE_MONTH_LOOP()
Dim rngMyRange As range
Dim cell As range
Set rngMyRange = Selection
For Each cell In rngMyRange.Cells
cell.Offset(0, 0) = "1-Jul-19"

cell.Offset(0, 1) = "1-Aug-19"

cell.Offset(0, 2) = "1-Sep-19"

Next cell

End Sub**






excel vba






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 1:43









ScottypScottyp

154




154













  • Woops, didn't notice the date part. Below will do the formatting and alignment. With the date, what are you doing with it? Is it just for a year? Why not hard codee if it is?

    – alowflyingpig
    Nov 14 '18 at 1:55











  • I have 750 worksheets that contain around 15,000 rows for a budgeting system. Last years Budgets go from July-2018 across to June-2020 (27 cells) I need to change these 27 cells in all relevant lines to July-2019 to June-2021. What I am trying to do is format only the cells I have modified to make sure they are in the "mmm-yy" format and right aligned. It stuffs up the readability of the sheet if everything is right aligned. In terms of your code wont that format the entire sheet in that format? (which is what I am trying to avoid).

    – Scottyp
    Nov 14 '18 at 2:10











  • no, it only formats row 1 in worksheet Sheet1. As I understand you want to loop through ALL worksheets within the workbook and make sure the format of row1 is "mmm-yy"?

    – alowflyingpig
    Nov 14 '18 at 2:33











  • If the below answer does what you want it to can you please ensure you mark as correct.

    – alowflyingpig
    Nov 14 '18 at 3:01



















  • Woops, didn't notice the date part. Below will do the formatting and alignment. With the date, what are you doing with it? Is it just for a year? Why not hard codee if it is?

    – alowflyingpig
    Nov 14 '18 at 1:55











  • I have 750 worksheets that contain around 15,000 rows for a budgeting system. Last years Budgets go from July-2018 across to June-2020 (27 cells) I need to change these 27 cells in all relevant lines to July-2019 to June-2021. What I am trying to do is format only the cells I have modified to make sure they are in the "mmm-yy" format and right aligned. It stuffs up the readability of the sheet if everything is right aligned. In terms of your code wont that format the entire sheet in that format? (which is what I am trying to avoid).

    – Scottyp
    Nov 14 '18 at 2:10











  • no, it only formats row 1 in worksheet Sheet1. As I understand you want to loop through ALL worksheets within the workbook and make sure the format of row1 is "mmm-yy"?

    – alowflyingpig
    Nov 14 '18 at 2:33











  • If the below answer does what you want it to can you please ensure you mark as correct.

    – alowflyingpig
    Nov 14 '18 at 3:01

















Woops, didn't notice the date part. Below will do the formatting and alignment. With the date, what are you doing with it? Is it just for a year? Why not hard codee if it is?

– alowflyingpig
Nov 14 '18 at 1:55





Woops, didn't notice the date part. Below will do the formatting and alignment. With the date, what are you doing with it? Is it just for a year? Why not hard codee if it is?

– alowflyingpig
Nov 14 '18 at 1:55













I have 750 worksheets that contain around 15,000 rows for a budgeting system. Last years Budgets go from July-2018 across to June-2020 (27 cells) I need to change these 27 cells in all relevant lines to July-2019 to June-2021. What I am trying to do is format only the cells I have modified to make sure they are in the "mmm-yy" format and right aligned. It stuffs up the readability of the sheet if everything is right aligned. In terms of your code wont that format the entire sheet in that format? (which is what I am trying to avoid).

– Scottyp
Nov 14 '18 at 2:10





I have 750 worksheets that contain around 15,000 rows for a budgeting system. Last years Budgets go from July-2018 across to June-2020 (27 cells) I need to change these 27 cells in all relevant lines to July-2019 to June-2021. What I am trying to do is format only the cells I have modified to make sure they are in the "mmm-yy" format and right aligned. It stuffs up the readability of the sheet if everything is right aligned. In terms of your code wont that format the entire sheet in that format? (which is what I am trying to avoid).

– Scottyp
Nov 14 '18 at 2:10













no, it only formats row 1 in worksheet Sheet1. As I understand you want to loop through ALL worksheets within the workbook and make sure the format of row1 is "mmm-yy"?

– alowflyingpig
Nov 14 '18 at 2:33





no, it only formats row 1 in worksheet Sheet1. As I understand you want to loop through ALL worksheets within the workbook and make sure the format of row1 is "mmm-yy"?

– alowflyingpig
Nov 14 '18 at 2:33













If the below answer does what you want it to can you please ensure you mark as correct.

– alowflyingpig
Nov 14 '18 at 3:01





If the below answer does what you want it to can you please ensure you mark as correct.

– alowflyingpig
Nov 14 '18 at 3:01












3 Answers
3






active

oldest

votes


















0














Back again, so if in @alowflyingpig and your boss' world less lines necessarily means more simple please see below a code that does exactly what your "full code" does... but in less lines...



Sub DATE_MONTHLY_LOOP()
Dim cell As Range, i As Integer
For Each cell In Selection.Cells: For i = 0 To 11: With cell.Offset(0, i): .Value = DateAdd("m", 1 + i, 43617): .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next i: With cell.Offset(0, 12): .Value = "FY20 TOTAL": .ColumnWidth = 11.3: .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next cell
End Sub





share|improve this answer

































    0














    PICTURE LINK



    This is what the sheet looks like. Basically I am using find / select and then on the highlighted cells I am running my macro. I am deliberately doing this one sheet at a time as there are some exceptions. The macro populates the adjacent cells using the cell.offset function.



    Ideally all I am trying to do is get these three commands on one line



    cell.Offset(0, 0).HorizontalAlignment = xlRight
    cell.Offset(0, 0).NumberFormat = "mmm-yy"
    cell.Offset(0, 0) = "1-Jul-19"


    i.e.
    cell.Offset(0, 0).HorizontalAlignment = xlRight.NumberFormat = "mmm-yy".value = "1-Jul-19"



    Anyone know if that can be done?



    FULL CODE:



    Sub DATE_MONTHLY_LOOP()

    Dim rngMyRange As range
    Dim cell As range

    Set rngMyRange = Selection

    For Each cell In rngMyRange.Cells

    cell.Offset(0, 0) = "1-Jul-19"
    cell.Offset(0, 0).HorizontalAlignment = xlRight
    cell.Offset(0, 0).NumberFormat = "mmm-yy"


    cell.Offset(0, 1) = "1-Aug-19"
    cell.Offset(0, 1).HorizontalAlignment = xlRight
    cell.Offset(0, 1).NumberFormat = "mmm-yy"


    cell.Offset(0, 2) = "1-Sep-19"
    cell.Offset(0, 2).HorizontalAlignment = xlRight
    cell.Offset(0, 2).NumberFormat = "mmm-yy"

    cell.Offset(0, 3) = "1-Oct-19"
    cell.Offset(0, 3).HorizontalAlignment = xlRight
    cell.Offset(0, 3).NumberFormat = "mmm-yy"

    cell.Offset(0, 4) = "1-Nov-19"
    cell.Offset(0, 4).HorizontalAlignment = xlRight
    cell.Offset(0, 4).NumberFormat = "mmm-yy"

    cell.Offset(0, 5) = "1-Dec-19"
    cell.Offset(0, 5).HorizontalAlignment = xlRight
    cell.Offset(0, 5).NumberFormat = "mmm-yy"

    cell.Offset(0, 6) = "1-Jan-20"
    cell.Offset(0, 6).HorizontalAlignment = xlRight
    cell.Offset(0, 6).NumberFormat = "mmm-yy"

    cell.Offset(0, 7) = "1-Feb-20"
    cell.Offset(0, 7).HorizontalAlignment = xlRight
    cell.Offset(0, 7).NumberFormat = "mmm-yy"

    cell.Offset(0, 8) = "1-Mar-20"
    cell.Offset(0, 8).HorizontalAlignment = xlRight
    cell.Offset(0, 8).NumberFormat = "mmm-yy"

    cell.Offset(0, 9) = "1-Apr-20"
    cell.Offset(0, 9).HorizontalAlignment = xlRight
    cell.Offset(0, 9).NumberFormat = "mmm-yy"

    cell.Offset(0, 10) = "1-May-20"
    cell.Offset(0, 10).HorizontalAlignment = xlRight
    cell.Offset(0, 10).NumberFormat = "mmm-yy"

    cell.Offset(0, 11) = "1-Jun-20"
    cell.Offset(0, 11).HorizontalAlignment = xlRight
    cell.Offset(0, 11).NumberFormat = "mmm-yy"

    cell.Offset(0, 12) = "FY20 TOTAL"
    cell.Offset(0, 12).ColumnWidth = 11.3
    cell.Offset(0, 12).HorizontalAlignment = xlRight
    cell.Offset(0, 12).NumberFormat = "mmm-yy"

    Next cell

    End sub





    share|improve this answer


























    • This is the longer code

      – Scottyp
      Nov 14 '18 at 4:43











    • Ok.... sad that you boss thinks less lines = more simple... anyway, if you are happy with your code, just put : like the following cell.Offset(0, 0).HorizontalAlignment = xlRight : cell.Offset(0, 0).NumberFormat = "mmm-yy" : cell.Offset(0, 0) = "1-Jul-19" Should work fine in one line

      – Display name
      Nov 14 '18 at 4:53











    • Less lines is more simple... You just need to understand how to write the less lines ;)

      – alowflyingpig
      Nov 14 '18 at 4:54











    • sure...........

      – Display name
      Nov 14 '18 at 4:57











    • That's pretty close thanks O.Pal, I was trying avoid having to write the cell.Offset(0, 0) x3 but at least its on one line is there likely to be a way to do that with the cell.Offset(0, 0) only once or am I dreaming / boss dreaming?

      – Scottyp
      Nov 14 '18 at 5:07





















    0














    Sub test()


    Dim LastRow As Long
    Dim irow As Long
    Dim jrow As Long
    Dim StartCol As Long
    Dim StartRow As Long



    For Each ws In ActiveWorkbook.Worksheets
    With ws.Select
    LastRow = ws.Range("G" & Rows.Count).End(xlUp).Row

    Set StartDate = Cells.Find(What:="Jul-17", After:=ws.Range("A1"), LookIn:=xlValues _
    , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    StartCol = StartDate.Column
    StartRow = StartDate.Row

    For irow = StartRow To LastRow
    Set Rng = ws.Range(Cells(irow, StartCol), Cells(irow, StartCol + 11))
    For Each Cell In Rng
    Cell.Value = DateAdd("yyyy", 1, Cell)
    Next Cell

    Rng.HorizontalAlignment = xlRight
    Rng.NumberFormat = "mmm-yy"

    irow = irow + 2
    Next irow

    For jrow = StartRow To LastRow
    Set Rng = ws.Range(Cells(jrow, StartCol + 12), Cells(jrow, StartCol + 12))
    For Each Cell In Rng
    Cell.Value = "FY19 Total"
    Next Cell
    jrow = jrow + 2
    Next jrow
    End With
    Next ws


    End Sub





    share|improve this answer


























    • Thanks but I want to limit the formatting to the cells I have modified using the offset function. The rest of the sheet needs to stay as is. See my pic below.

      – Scottyp
      Nov 14 '18 at 4:41











    • @Scottyp There is no difference if you format the style of the dates. Since you are changing each date, the code ensure the same format is used throughout

      – alowflyingpig
      Nov 14 '18 at 4:56













    • This is for a budgeting worksheet so under each date is a dollar value for a respective cost line (or general ledger code for the accountants). At the moment the above is formatting the dollars as days.

      – Scottyp
      Nov 14 '18 at 5:03











    • What cell is the first date in?

      – alowflyingpig
      Nov 14 '18 at 5:20











    • Dates usually start in column 3, but in some cases 4 or 5 also.

      – Scottyp
      Nov 14 '18 at 21:21











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291998%2fformatting-cells-within-a-selection-loop%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Back again, so if in @alowflyingpig and your boss' world less lines necessarily means more simple please see below a code that does exactly what your "full code" does... but in less lines...



    Sub DATE_MONTHLY_LOOP()
    Dim cell As Range, i As Integer
    For Each cell In Selection.Cells: For i = 0 To 11: With cell.Offset(0, i): .Value = DateAdd("m", 1 + i, 43617): .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next i: With cell.Offset(0, 12): .Value = "FY20 TOTAL": .ColumnWidth = 11.3: .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next cell
    End Sub





    share|improve this answer






























      0














      Back again, so if in @alowflyingpig and your boss' world less lines necessarily means more simple please see below a code that does exactly what your "full code" does... but in less lines...



      Sub DATE_MONTHLY_LOOP()
      Dim cell As Range, i As Integer
      For Each cell In Selection.Cells: For i = 0 To 11: With cell.Offset(0, i): .Value = DateAdd("m", 1 + i, 43617): .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next i: With cell.Offset(0, 12): .Value = "FY20 TOTAL": .ColumnWidth = 11.3: .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next cell
      End Sub





      share|improve this answer




























        0












        0








        0







        Back again, so if in @alowflyingpig and your boss' world less lines necessarily means more simple please see below a code that does exactly what your "full code" does... but in less lines...



        Sub DATE_MONTHLY_LOOP()
        Dim cell As Range, i As Integer
        For Each cell In Selection.Cells: For i = 0 To 11: With cell.Offset(0, i): .Value = DateAdd("m", 1 + i, 43617): .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next i: With cell.Offset(0, 12): .Value = "FY20 TOTAL": .ColumnWidth = 11.3: .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next cell
        End Sub





        share|improve this answer















        Back again, so if in @alowflyingpig and your boss' world less lines necessarily means more simple please see below a code that does exactly what your "full code" does... but in less lines...



        Sub DATE_MONTHLY_LOOP()
        Dim cell As Range, i As Integer
        For Each cell In Selection.Cells: For i = 0 To 11: With cell.Offset(0, i): .Value = DateAdd("m", 1 + i, 43617): .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next i: With cell.Offset(0, 12): .Value = "FY20 TOTAL": .ColumnWidth = 11.3: .HorizontalAlignment = xlRight: .NumberFormat = "mmm-yy": End With: Next cell
        End Sub






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 14 '18 at 23:13

























        answered Nov 14 '18 at 23:02









        Display nameDisplay name

        53416




        53416

























            0














            PICTURE LINK



            This is what the sheet looks like. Basically I am using find / select and then on the highlighted cells I am running my macro. I am deliberately doing this one sheet at a time as there are some exceptions. The macro populates the adjacent cells using the cell.offset function.



            Ideally all I am trying to do is get these three commands on one line



            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"
            cell.Offset(0, 0) = "1-Jul-19"


            i.e.
            cell.Offset(0, 0).HorizontalAlignment = xlRight.NumberFormat = "mmm-yy".value = "1-Jul-19"



            Anyone know if that can be done?



            FULL CODE:



            Sub DATE_MONTHLY_LOOP()

            Dim rngMyRange As range
            Dim cell As range

            Set rngMyRange = Selection

            For Each cell In rngMyRange.Cells

            cell.Offset(0, 0) = "1-Jul-19"
            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"


            cell.Offset(0, 1) = "1-Aug-19"
            cell.Offset(0, 1).HorizontalAlignment = xlRight
            cell.Offset(0, 1).NumberFormat = "mmm-yy"


            cell.Offset(0, 2) = "1-Sep-19"
            cell.Offset(0, 2).HorizontalAlignment = xlRight
            cell.Offset(0, 2).NumberFormat = "mmm-yy"

            cell.Offset(0, 3) = "1-Oct-19"
            cell.Offset(0, 3).HorizontalAlignment = xlRight
            cell.Offset(0, 3).NumberFormat = "mmm-yy"

            cell.Offset(0, 4) = "1-Nov-19"
            cell.Offset(0, 4).HorizontalAlignment = xlRight
            cell.Offset(0, 4).NumberFormat = "mmm-yy"

            cell.Offset(0, 5) = "1-Dec-19"
            cell.Offset(0, 5).HorizontalAlignment = xlRight
            cell.Offset(0, 5).NumberFormat = "mmm-yy"

            cell.Offset(0, 6) = "1-Jan-20"
            cell.Offset(0, 6).HorizontalAlignment = xlRight
            cell.Offset(0, 6).NumberFormat = "mmm-yy"

            cell.Offset(0, 7) = "1-Feb-20"
            cell.Offset(0, 7).HorizontalAlignment = xlRight
            cell.Offset(0, 7).NumberFormat = "mmm-yy"

            cell.Offset(0, 8) = "1-Mar-20"
            cell.Offset(0, 8).HorizontalAlignment = xlRight
            cell.Offset(0, 8).NumberFormat = "mmm-yy"

            cell.Offset(0, 9) = "1-Apr-20"
            cell.Offset(0, 9).HorizontalAlignment = xlRight
            cell.Offset(0, 9).NumberFormat = "mmm-yy"

            cell.Offset(0, 10) = "1-May-20"
            cell.Offset(0, 10).HorizontalAlignment = xlRight
            cell.Offset(0, 10).NumberFormat = "mmm-yy"

            cell.Offset(0, 11) = "1-Jun-20"
            cell.Offset(0, 11).HorizontalAlignment = xlRight
            cell.Offset(0, 11).NumberFormat = "mmm-yy"

            cell.Offset(0, 12) = "FY20 TOTAL"
            cell.Offset(0, 12).ColumnWidth = 11.3
            cell.Offset(0, 12).HorizontalAlignment = xlRight
            cell.Offset(0, 12).NumberFormat = "mmm-yy"

            Next cell

            End sub





            share|improve this answer


























            • This is the longer code

              – Scottyp
              Nov 14 '18 at 4:43











            • Ok.... sad that you boss thinks less lines = more simple... anyway, if you are happy with your code, just put : like the following cell.Offset(0, 0).HorizontalAlignment = xlRight : cell.Offset(0, 0).NumberFormat = "mmm-yy" : cell.Offset(0, 0) = "1-Jul-19" Should work fine in one line

              – Display name
              Nov 14 '18 at 4:53











            • Less lines is more simple... You just need to understand how to write the less lines ;)

              – alowflyingpig
              Nov 14 '18 at 4:54











            • sure...........

              – Display name
              Nov 14 '18 at 4:57











            • That's pretty close thanks O.Pal, I was trying avoid having to write the cell.Offset(0, 0) x3 but at least its on one line is there likely to be a way to do that with the cell.Offset(0, 0) only once or am I dreaming / boss dreaming?

              – Scottyp
              Nov 14 '18 at 5:07


















            0














            PICTURE LINK



            This is what the sheet looks like. Basically I am using find / select and then on the highlighted cells I am running my macro. I am deliberately doing this one sheet at a time as there are some exceptions. The macro populates the adjacent cells using the cell.offset function.



            Ideally all I am trying to do is get these three commands on one line



            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"
            cell.Offset(0, 0) = "1-Jul-19"


            i.e.
            cell.Offset(0, 0).HorizontalAlignment = xlRight.NumberFormat = "mmm-yy".value = "1-Jul-19"



            Anyone know if that can be done?



            FULL CODE:



            Sub DATE_MONTHLY_LOOP()

            Dim rngMyRange As range
            Dim cell As range

            Set rngMyRange = Selection

            For Each cell In rngMyRange.Cells

            cell.Offset(0, 0) = "1-Jul-19"
            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"


            cell.Offset(0, 1) = "1-Aug-19"
            cell.Offset(0, 1).HorizontalAlignment = xlRight
            cell.Offset(0, 1).NumberFormat = "mmm-yy"


            cell.Offset(0, 2) = "1-Sep-19"
            cell.Offset(0, 2).HorizontalAlignment = xlRight
            cell.Offset(0, 2).NumberFormat = "mmm-yy"

            cell.Offset(0, 3) = "1-Oct-19"
            cell.Offset(0, 3).HorizontalAlignment = xlRight
            cell.Offset(0, 3).NumberFormat = "mmm-yy"

            cell.Offset(0, 4) = "1-Nov-19"
            cell.Offset(0, 4).HorizontalAlignment = xlRight
            cell.Offset(0, 4).NumberFormat = "mmm-yy"

            cell.Offset(0, 5) = "1-Dec-19"
            cell.Offset(0, 5).HorizontalAlignment = xlRight
            cell.Offset(0, 5).NumberFormat = "mmm-yy"

            cell.Offset(0, 6) = "1-Jan-20"
            cell.Offset(0, 6).HorizontalAlignment = xlRight
            cell.Offset(0, 6).NumberFormat = "mmm-yy"

            cell.Offset(0, 7) = "1-Feb-20"
            cell.Offset(0, 7).HorizontalAlignment = xlRight
            cell.Offset(0, 7).NumberFormat = "mmm-yy"

            cell.Offset(0, 8) = "1-Mar-20"
            cell.Offset(0, 8).HorizontalAlignment = xlRight
            cell.Offset(0, 8).NumberFormat = "mmm-yy"

            cell.Offset(0, 9) = "1-Apr-20"
            cell.Offset(0, 9).HorizontalAlignment = xlRight
            cell.Offset(0, 9).NumberFormat = "mmm-yy"

            cell.Offset(0, 10) = "1-May-20"
            cell.Offset(0, 10).HorizontalAlignment = xlRight
            cell.Offset(0, 10).NumberFormat = "mmm-yy"

            cell.Offset(0, 11) = "1-Jun-20"
            cell.Offset(0, 11).HorizontalAlignment = xlRight
            cell.Offset(0, 11).NumberFormat = "mmm-yy"

            cell.Offset(0, 12) = "FY20 TOTAL"
            cell.Offset(0, 12).ColumnWidth = 11.3
            cell.Offset(0, 12).HorizontalAlignment = xlRight
            cell.Offset(0, 12).NumberFormat = "mmm-yy"

            Next cell

            End sub





            share|improve this answer


























            • This is the longer code

              – Scottyp
              Nov 14 '18 at 4:43











            • Ok.... sad that you boss thinks less lines = more simple... anyway, if you are happy with your code, just put : like the following cell.Offset(0, 0).HorizontalAlignment = xlRight : cell.Offset(0, 0).NumberFormat = "mmm-yy" : cell.Offset(0, 0) = "1-Jul-19" Should work fine in one line

              – Display name
              Nov 14 '18 at 4:53











            • Less lines is more simple... You just need to understand how to write the less lines ;)

              – alowflyingpig
              Nov 14 '18 at 4:54











            • sure...........

              – Display name
              Nov 14 '18 at 4:57











            • That's pretty close thanks O.Pal, I was trying avoid having to write the cell.Offset(0, 0) x3 but at least its on one line is there likely to be a way to do that with the cell.Offset(0, 0) only once or am I dreaming / boss dreaming?

              – Scottyp
              Nov 14 '18 at 5:07
















            0












            0








            0







            PICTURE LINK



            This is what the sheet looks like. Basically I am using find / select and then on the highlighted cells I am running my macro. I am deliberately doing this one sheet at a time as there are some exceptions. The macro populates the adjacent cells using the cell.offset function.



            Ideally all I am trying to do is get these three commands on one line



            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"
            cell.Offset(0, 0) = "1-Jul-19"


            i.e.
            cell.Offset(0, 0).HorizontalAlignment = xlRight.NumberFormat = "mmm-yy".value = "1-Jul-19"



            Anyone know if that can be done?



            FULL CODE:



            Sub DATE_MONTHLY_LOOP()

            Dim rngMyRange As range
            Dim cell As range

            Set rngMyRange = Selection

            For Each cell In rngMyRange.Cells

            cell.Offset(0, 0) = "1-Jul-19"
            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"


            cell.Offset(0, 1) = "1-Aug-19"
            cell.Offset(0, 1).HorizontalAlignment = xlRight
            cell.Offset(0, 1).NumberFormat = "mmm-yy"


            cell.Offset(0, 2) = "1-Sep-19"
            cell.Offset(0, 2).HorizontalAlignment = xlRight
            cell.Offset(0, 2).NumberFormat = "mmm-yy"

            cell.Offset(0, 3) = "1-Oct-19"
            cell.Offset(0, 3).HorizontalAlignment = xlRight
            cell.Offset(0, 3).NumberFormat = "mmm-yy"

            cell.Offset(0, 4) = "1-Nov-19"
            cell.Offset(0, 4).HorizontalAlignment = xlRight
            cell.Offset(0, 4).NumberFormat = "mmm-yy"

            cell.Offset(0, 5) = "1-Dec-19"
            cell.Offset(0, 5).HorizontalAlignment = xlRight
            cell.Offset(0, 5).NumberFormat = "mmm-yy"

            cell.Offset(0, 6) = "1-Jan-20"
            cell.Offset(0, 6).HorizontalAlignment = xlRight
            cell.Offset(0, 6).NumberFormat = "mmm-yy"

            cell.Offset(0, 7) = "1-Feb-20"
            cell.Offset(0, 7).HorizontalAlignment = xlRight
            cell.Offset(0, 7).NumberFormat = "mmm-yy"

            cell.Offset(0, 8) = "1-Mar-20"
            cell.Offset(0, 8).HorizontalAlignment = xlRight
            cell.Offset(0, 8).NumberFormat = "mmm-yy"

            cell.Offset(0, 9) = "1-Apr-20"
            cell.Offset(0, 9).HorizontalAlignment = xlRight
            cell.Offset(0, 9).NumberFormat = "mmm-yy"

            cell.Offset(0, 10) = "1-May-20"
            cell.Offset(0, 10).HorizontalAlignment = xlRight
            cell.Offset(0, 10).NumberFormat = "mmm-yy"

            cell.Offset(0, 11) = "1-Jun-20"
            cell.Offset(0, 11).HorizontalAlignment = xlRight
            cell.Offset(0, 11).NumberFormat = "mmm-yy"

            cell.Offset(0, 12) = "FY20 TOTAL"
            cell.Offset(0, 12).ColumnWidth = 11.3
            cell.Offset(0, 12).HorizontalAlignment = xlRight
            cell.Offset(0, 12).NumberFormat = "mmm-yy"

            Next cell

            End sub





            share|improve this answer















            PICTURE LINK



            This is what the sheet looks like. Basically I am using find / select and then on the highlighted cells I am running my macro. I am deliberately doing this one sheet at a time as there are some exceptions. The macro populates the adjacent cells using the cell.offset function.



            Ideally all I am trying to do is get these three commands on one line



            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"
            cell.Offset(0, 0) = "1-Jul-19"


            i.e.
            cell.Offset(0, 0).HorizontalAlignment = xlRight.NumberFormat = "mmm-yy".value = "1-Jul-19"



            Anyone know if that can be done?



            FULL CODE:



            Sub DATE_MONTHLY_LOOP()

            Dim rngMyRange As range
            Dim cell As range

            Set rngMyRange = Selection

            For Each cell In rngMyRange.Cells

            cell.Offset(0, 0) = "1-Jul-19"
            cell.Offset(0, 0).HorizontalAlignment = xlRight
            cell.Offset(0, 0).NumberFormat = "mmm-yy"


            cell.Offset(0, 1) = "1-Aug-19"
            cell.Offset(0, 1).HorizontalAlignment = xlRight
            cell.Offset(0, 1).NumberFormat = "mmm-yy"


            cell.Offset(0, 2) = "1-Sep-19"
            cell.Offset(0, 2).HorizontalAlignment = xlRight
            cell.Offset(0, 2).NumberFormat = "mmm-yy"

            cell.Offset(0, 3) = "1-Oct-19"
            cell.Offset(0, 3).HorizontalAlignment = xlRight
            cell.Offset(0, 3).NumberFormat = "mmm-yy"

            cell.Offset(0, 4) = "1-Nov-19"
            cell.Offset(0, 4).HorizontalAlignment = xlRight
            cell.Offset(0, 4).NumberFormat = "mmm-yy"

            cell.Offset(0, 5) = "1-Dec-19"
            cell.Offset(0, 5).HorizontalAlignment = xlRight
            cell.Offset(0, 5).NumberFormat = "mmm-yy"

            cell.Offset(0, 6) = "1-Jan-20"
            cell.Offset(0, 6).HorizontalAlignment = xlRight
            cell.Offset(0, 6).NumberFormat = "mmm-yy"

            cell.Offset(0, 7) = "1-Feb-20"
            cell.Offset(0, 7).HorizontalAlignment = xlRight
            cell.Offset(0, 7).NumberFormat = "mmm-yy"

            cell.Offset(0, 8) = "1-Mar-20"
            cell.Offset(0, 8).HorizontalAlignment = xlRight
            cell.Offset(0, 8).NumberFormat = "mmm-yy"

            cell.Offset(0, 9) = "1-Apr-20"
            cell.Offset(0, 9).HorizontalAlignment = xlRight
            cell.Offset(0, 9).NumberFormat = "mmm-yy"

            cell.Offset(0, 10) = "1-May-20"
            cell.Offset(0, 10).HorizontalAlignment = xlRight
            cell.Offset(0, 10).NumberFormat = "mmm-yy"

            cell.Offset(0, 11) = "1-Jun-20"
            cell.Offset(0, 11).HorizontalAlignment = xlRight
            cell.Offset(0, 11).NumberFormat = "mmm-yy"

            cell.Offset(0, 12) = "FY20 TOTAL"
            cell.Offset(0, 12).ColumnWidth = 11.3
            cell.Offset(0, 12).HorizontalAlignment = xlRight
            cell.Offset(0, 12).NumberFormat = "mmm-yy"

            Next cell

            End sub






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 14 '18 at 4:44

























            answered Nov 14 '18 at 4:15









            ScottypScottyp

            154




            154













            • This is the longer code

              – Scottyp
              Nov 14 '18 at 4:43











            • Ok.... sad that you boss thinks less lines = more simple... anyway, if you are happy with your code, just put : like the following cell.Offset(0, 0).HorizontalAlignment = xlRight : cell.Offset(0, 0).NumberFormat = "mmm-yy" : cell.Offset(0, 0) = "1-Jul-19" Should work fine in one line

              – Display name
              Nov 14 '18 at 4:53











            • Less lines is more simple... You just need to understand how to write the less lines ;)

              – alowflyingpig
              Nov 14 '18 at 4:54











            • sure...........

              – Display name
              Nov 14 '18 at 4:57











            • That's pretty close thanks O.Pal, I was trying avoid having to write the cell.Offset(0, 0) x3 but at least its on one line is there likely to be a way to do that with the cell.Offset(0, 0) only once or am I dreaming / boss dreaming?

              – Scottyp
              Nov 14 '18 at 5:07





















            • This is the longer code

              – Scottyp
              Nov 14 '18 at 4:43











            • Ok.... sad that you boss thinks less lines = more simple... anyway, if you are happy with your code, just put : like the following cell.Offset(0, 0).HorizontalAlignment = xlRight : cell.Offset(0, 0).NumberFormat = "mmm-yy" : cell.Offset(0, 0) = "1-Jul-19" Should work fine in one line

              – Display name
              Nov 14 '18 at 4:53











            • Less lines is more simple... You just need to understand how to write the less lines ;)

              – alowflyingpig
              Nov 14 '18 at 4:54











            • sure...........

              – Display name
              Nov 14 '18 at 4:57











            • That's pretty close thanks O.Pal, I was trying avoid having to write the cell.Offset(0, 0) x3 but at least its on one line is there likely to be a way to do that with the cell.Offset(0, 0) only once or am I dreaming / boss dreaming?

              – Scottyp
              Nov 14 '18 at 5:07



















            This is the longer code

            – Scottyp
            Nov 14 '18 at 4:43





            This is the longer code

            – Scottyp
            Nov 14 '18 at 4:43













            Ok.... sad that you boss thinks less lines = more simple... anyway, if you are happy with your code, just put : like the following cell.Offset(0, 0).HorizontalAlignment = xlRight : cell.Offset(0, 0).NumberFormat = "mmm-yy" : cell.Offset(0, 0) = "1-Jul-19" Should work fine in one line

            – Display name
            Nov 14 '18 at 4:53





            Ok.... sad that you boss thinks less lines = more simple... anyway, if you are happy with your code, just put : like the following cell.Offset(0, 0).HorizontalAlignment = xlRight : cell.Offset(0, 0).NumberFormat = "mmm-yy" : cell.Offset(0, 0) = "1-Jul-19" Should work fine in one line

            – Display name
            Nov 14 '18 at 4:53













            Less lines is more simple... You just need to understand how to write the less lines ;)

            – alowflyingpig
            Nov 14 '18 at 4:54





            Less lines is more simple... You just need to understand how to write the less lines ;)

            – alowflyingpig
            Nov 14 '18 at 4:54













            sure...........

            – Display name
            Nov 14 '18 at 4:57





            sure...........

            – Display name
            Nov 14 '18 at 4:57













            That's pretty close thanks O.Pal, I was trying avoid having to write the cell.Offset(0, 0) x3 but at least its on one line is there likely to be a way to do that with the cell.Offset(0, 0) only once or am I dreaming / boss dreaming?

            – Scottyp
            Nov 14 '18 at 5:07







            That's pretty close thanks O.Pal, I was trying avoid having to write the cell.Offset(0, 0) x3 but at least its on one line is there likely to be a way to do that with the cell.Offset(0, 0) only once or am I dreaming / boss dreaming?

            – Scottyp
            Nov 14 '18 at 5:07













            0














            Sub test()


            Dim LastRow As Long
            Dim irow As Long
            Dim jrow As Long
            Dim StartCol As Long
            Dim StartRow As Long



            For Each ws In ActiveWorkbook.Worksheets
            With ws.Select
            LastRow = ws.Range("G" & Rows.Count).End(xlUp).Row

            Set StartDate = Cells.Find(What:="Jul-17", After:=ws.Range("A1"), LookIn:=xlValues _
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
            StartCol = StartDate.Column
            StartRow = StartDate.Row

            For irow = StartRow To LastRow
            Set Rng = ws.Range(Cells(irow, StartCol), Cells(irow, StartCol + 11))
            For Each Cell In Rng
            Cell.Value = DateAdd("yyyy", 1, Cell)
            Next Cell

            Rng.HorizontalAlignment = xlRight
            Rng.NumberFormat = "mmm-yy"

            irow = irow + 2
            Next irow

            For jrow = StartRow To LastRow
            Set Rng = ws.Range(Cells(jrow, StartCol + 12), Cells(jrow, StartCol + 12))
            For Each Cell In Rng
            Cell.Value = "FY19 Total"
            Next Cell
            jrow = jrow + 2
            Next jrow
            End With
            Next ws


            End Sub





            share|improve this answer


























            • Thanks but I want to limit the formatting to the cells I have modified using the offset function. The rest of the sheet needs to stay as is. See my pic below.

              – Scottyp
              Nov 14 '18 at 4:41











            • @Scottyp There is no difference if you format the style of the dates. Since you are changing each date, the code ensure the same format is used throughout

              – alowflyingpig
              Nov 14 '18 at 4:56













            • This is for a budgeting worksheet so under each date is a dollar value for a respective cost line (or general ledger code for the accountants). At the moment the above is formatting the dollars as days.

              – Scottyp
              Nov 14 '18 at 5:03











            • What cell is the first date in?

              – alowflyingpig
              Nov 14 '18 at 5:20











            • Dates usually start in column 3, but in some cases 4 or 5 also.

              – Scottyp
              Nov 14 '18 at 21:21
















            0














            Sub test()


            Dim LastRow As Long
            Dim irow As Long
            Dim jrow As Long
            Dim StartCol As Long
            Dim StartRow As Long



            For Each ws In ActiveWorkbook.Worksheets
            With ws.Select
            LastRow = ws.Range("G" & Rows.Count).End(xlUp).Row

            Set StartDate = Cells.Find(What:="Jul-17", After:=ws.Range("A1"), LookIn:=xlValues _
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
            StartCol = StartDate.Column
            StartRow = StartDate.Row

            For irow = StartRow To LastRow
            Set Rng = ws.Range(Cells(irow, StartCol), Cells(irow, StartCol + 11))
            For Each Cell In Rng
            Cell.Value = DateAdd("yyyy", 1, Cell)
            Next Cell

            Rng.HorizontalAlignment = xlRight
            Rng.NumberFormat = "mmm-yy"

            irow = irow + 2
            Next irow

            For jrow = StartRow To LastRow
            Set Rng = ws.Range(Cells(jrow, StartCol + 12), Cells(jrow, StartCol + 12))
            For Each Cell In Rng
            Cell.Value = "FY19 Total"
            Next Cell
            jrow = jrow + 2
            Next jrow
            End With
            Next ws


            End Sub





            share|improve this answer


























            • Thanks but I want to limit the formatting to the cells I have modified using the offset function. The rest of the sheet needs to stay as is. See my pic below.

              – Scottyp
              Nov 14 '18 at 4:41











            • @Scottyp There is no difference if you format the style of the dates. Since you are changing each date, the code ensure the same format is used throughout

              – alowflyingpig
              Nov 14 '18 at 4:56













            • This is for a budgeting worksheet so under each date is a dollar value for a respective cost line (or general ledger code for the accountants). At the moment the above is formatting the dollars as days.

              – Scottyp
              Nov 14 '18 at 5:03











            • What cell is the first date in?

              – alowflyingpig
              Nov 14 '18 at 5:20











            • Dates usually start in column 3, but in some cases 4 or 5 also.

              – Scottyp
              Nov 14 '18 at 21:21














            0












            0








            0







            Sub test()


            Dim LastRow As Long
            Dim irow As Long
            Dim jrow As Long
            Dim StartCol As Long
            Dim StartRow As Long



            For Each ws In ActiveWorkbook.Worksheets
            With ws.Select
            LastRow = ws.Range("G" & Rows.Count).End(xlUp).Row

            Set StartDate = Cells.Find(What:="Jul-17", After:=ws.Range("A1"), LookIn:=xlValues _
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
            StartCol = StartDate.Column
            StartRow = StartDate.Row

            For irow = StartRow To LastRow
            Set Rng = ws.Range(Cells(irow, StartCol), Cells(irow, StartCol + 11))
            For Each Cell In Rng
            Cell.Value = DateAdd("yyyy", 1, Cell)
            Next Cell

            Rng.HorizontalAlignment = xlRight
            Rng.NumberFormat = "mmm-yy"

            irow = irow + 2
            Next irow

            For jrow = StartRow To LastRow
            Set Rng = ws.Range(Cells(jrow, StartCol + 12), Cells(jrow, StartCol + 12))
            For Each Cell In Rng
            Cell.Value = "FY19 Total"
            Next Cell
            jrow = jrow + 2
            Next jrow
            End With
            Next ws


            End Sub





            share|improve this answer















            Sub test()


            Dim LastRow As Long
            Dim irow As Long
            Dim jrow As Long
            Dim StartCol As Long
            Dim StartRow As Long



            For Each ws In ActiveWorkbook.Worksheets
            With ws.Select
            LastRow = ws.Range("G" & Rows.Count).End(xlUp).Row

            Set StartDate = Cells.Find(What:="Jul-17", After:=ws.Range("A1"), LookIn:=xlValues _
            , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
            StartCol = StartDate.Column
            StartRow = StartDate.Row

            For irow = StartRow To LastRow
            Set Rng = ws.Range(Cells(irow, StartCol), Cells(irow, StartCol + 11))
            For Each Cell In Rng
            Cell.Value = DateAdd("yyyy", 1, Cell)
            Next Cell

            Rng.HorizontalAlignment = xlRight
            Rng.NumberFormat = "mmm-yy"

            irow = irow + 2
            Next irow

            For jrow = StartRow To LastRow
            Set Rng = ws.Range(Cells(jrow, StartCol + 12), Cells(jrow, StartCol + 12))
            For Each Cell In Rng
            Cell.Value = "FY19 Total"
            Next Cell
            jrow = jrow + 2
            Next jrow
            End With
            Next ws


            End Sub






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 14 '18 at 23:29

























            answered Nov 14 '18 at 1:53









            alowflyingpigalowflyingpig

            1809




            1809













            • Thanks but I want to limit the formatting to the cells I have modified using the offset function. The rest of the sheet needs to stay as is. See my pic below.

              – Scottyp
              Nov 14 '18 at 4:41











            • @Scottyp There is no difference if you format the style of the dates. Since you are changing each date, the code ensure the same format is used throughout

              – alowflyingpig
              Nov 14 '18 at 4:56













            • This is for a budgeting worksheet so under each date is a dollar value for a respective cost line (or general ledger code for the accountants). At the moment the above is formatting the dollars as days.

              – Scottyp
              Nov 14 '18 at 5:03











            • What cell is the first date in?

              – alowflyingpig
              Nov 14 '18 at 5:20











            • Dates usually start in column 3, but in some cases 4 or 5 also.

              – Scottyp
              Nov 14 '18 at 21:21



















            • Thanks but I want to limit the formatting to the cells I have modified using the offset function. The rest of the sheet needs to stay as is. See my pic below.

              – Scottyp
              Nov 14 '18 at 4:41











            • @Scottyp There is no difference if you format the style of the dates. Since you are changing each date, the code ensure the same format is used throughout

              – alowflyingpig
              Nov 14 '18 at 4:56













            • This is for a budgeting worksheet so under each date is a dollar value for a respective cost line (or general ledger code for the accountants). At the moment the above is formatting the dollars as days.

              – Scottyp
              Nov 14 '18 at 5:03











            • What cell is the first date in?

              – alowflyingpig
              Nov 14 '18 at 5:20











            • Dates usually start in column 3, but in some cases 4 or 5 also.

              – Scottyp
              Nov 14 '18 at 21:21

















            Thanks but I want to limit the formatting to the cells I have modified using the offset function. The rest of the sheet needs to stay as is. See my pic below.

            – Scottyp
            Nov 14 '18 at 4:41





            Thanks but I want to limit the formatting to the cells I have modified using the offset function. The rest of the sheet needs to stay as is. See my pic below.

            – Scottyp
            Nov 14 '18 at 4:41













            @Scottyp There is no difference if you format the style of the dates. Since you are changing each date, the code ensure the same format is used throughout

            – alowflyingpig
            Nov 14 '18 at 4:56







            @Scottyp There is no difference if you format the style of the dates. Since you are changing each date, the code ensure the same format is used throughout

            – alowflyingpig
            Nov 14 '18 at 4:56















            This is for a budgeting worksheet so under each date is a dollar value for a respective cost line (or general ledger code for the accountants). At the moment the above is formatting the dollars as days.

            – Scottyp
            Nov 14 '18 at 5:03





            This is for a budgeting worksheet so under each date is a dollar value for a respective cost line (or general ledger code for the accountants). At the moment the above is formatting the dollars as days.

            – Scottyp
            Nov 14 '18 at 5:03













            What cell is the first date in?

            – alowflyingpig
            Nov 14 '18 at 5:20





            What cell is the first date in?

            – alowflyingpig
            Nov 14 '18 at 5:20













            Dates usually start in column 3, but in some cases 4 or 5 also.

            – Scottyp
            Nov 14 '18 at 21:21





            Dates usually start in column 3, but in some cases 4 or 5 also.

            – Scottyp
            Nov 14 '18 at 21:21


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291998%2fformatting-cells-within-a-selection-loop%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine