Filldown columns from cells value in each worksheet



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















What I am trying to do is to take values from specific cells and make them a filldown column. I have multiple worksheets with different values in them.



This code is working as expected with one worksheet :



Sub Formatting_one()

Range("A12").Value = Range("M6").Value
Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

End Sub


Then, I started to try the same thing but with looping through worksheets. That's the point I am stuck with. Here is my code for this :



Sub Formatting_many()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.[A1].Resize(, 6).EntireColumn.Insert

ws.Range("A12").Value = ws.Range("M6").Value
ws.Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("B12").Value = ws.Range("M7").Value
ws.Range("B12:B" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("C12").Value = ws.Range("M8").Value
ws.Range("C12:C" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("D12").Value = ws.Range("I5").Value
ws.Range("D12:D" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("E12").Value = ws.Range("I4").Value
ws.Range("E12:E" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("F12").Value = ws.Range("I6").Value
ws.Range("F12:F" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("G12").Value = ws.Range("I7").Value
ws.Range("G12:G" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

Next ws

End Sub


I did a step by step, and the result is that the cell is copied in the first cell of the filldown range cells but then it's deleted. Can somebody help ?










share|improve this question






















  • In Cells(Rows.Count, 7).End(xlUp).Row you need to specify the worksheet: ws.Cells(ws.Rows.Count, 7).End(xlUp).Row Also note that 7 means column G. Check if that is the correct column to look for the last used row.

    – Pᴇʜ
    Nov 15 '18 at 15:39












  • Yeah, I tested that but I think Excel understands the reference between the Range() as it doesn't change anything if I put the sheet specification or not. Still have the same issue! The rows are all equal, the "7" was random, just in case I delete things while formatting my sheets :p

    – MrRarri
    Nov 15 '18 at 15:44


















1















What I am trying to do is to take values from specific cells and make them a filldown column. I have multiple worksheets with different values in them.



This code is working as expected with one worksheet :



Sub Formatting_one()

Range("A12").Value = Range("M6").Value
Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

End Sub


Then, I started to try the same thing but with looping through worksheets. That's the point I am stuck with. Here is my code for this :



Sub Formatting_many()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.[A1].Resize(, 6).EntireColumn.Insert

ws.Range("A12").Value = ws.Range("M6").Value
ws.Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("B12").Value = ws.Range("M7").Value
ws.Range("B12:B" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("C12").Value = ws.Range("M8").Value
ws.Range("C12:C" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("D12").Value = ws.Range("I5").Value
ws.Range("D12:D" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("E12").Value = ws.Range("I4").Value
ws.Range("E12:E" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("F12").Value = ws.Range("I6").Value
ws.Range("F12:F" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("G12").Value = ws.Range("I7").Value
ws.Range("G12:G" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

Next ws

End Sub


I did a step by step, and the result is that the cell is copied in the first cell of the filldown range cells but then it's deleted. Can somebody help ?










share|improve this question






















  • In Cells(Rows.Count, 7).End(xlUp).Row you need to specify the worksheet: ws.Cells(ws.Rows.Count, 7).End(xlUp).Row Also note that 7 means column G. Check if that is the correct column to look for the last used row.

    – Pᴇʜ
    Nov 15 '18 at 15:39












  • Yeah, I tested that but I think Excel understands the reference between the Range() as it doesn't change anything if I put the sheet specification or not. Still have the same issue! The rows are all equal, the "7" was random, just in case I delete things while formatting my sheets :p

    – MrRarri
    Nov 15 '18 at 15:44














1












1








1








What I am trying to do is to take values from specific cells and make them a filldown column. I have multiple worksheets with different values in them.



This code is working as expected with one worksheet :



Sub Formatting_one()

Range("A12").Value = Range("M6").Value
Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

End Sub


Then, I started to try the same thing but with looping through worksheets. That's the point I am stuck with. Here is my code for this :



Sub Formatting_many()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.[A1].Resize(, 6).EntireColumn.Insert

ws.Range("A12").Value = ws.Range("M6").Value
ws.Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("B12").Value = ws.Range("M7").Value
ws.Range("B12:B" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("C12").Value = ws.Range("M8").Value
ws.Range("C12:C" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("D12").Value = ws.Range("I5").Value
ws.Range("D12:D" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("E12").Value = ws.Range("I4").Value
ws.Range("E12:E" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("F12").Value = ws.Range("I6").Value
ws.Range("F12:F" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("G12").Value = ws.Range("I7").Value
ws.Range("G12:G" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

Next ws

End Sub


I did a step by step, and the result is that the cell is copied in the first cell of the filldown range cells but then it's deleted. Can somebody help ?










share|improve this question














What I am trying to do is to take values from specific cells and make them a filldown column. I have multiple worksheets with different values in them.



This code is working as expected with one worksheet :



Sub Formatting_one()

Range("A12").Value = Range("M6").Value
Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

End Sub


Then, I started to try the same thing but with looping through worksheets. That's the point I am stuck with. Here is my code for this :



Sub Formatting_many()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
ws.[A1].Resize(, 6).EntireColumn.Insert

ws.Range("A12").Value = ws.Range("M6").Value
ws.Range("A12:A" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("B12").Value = ws.Range("M7").Value
ws.Range("B12:B" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("C12").Value = ws.Range("M8").Value
ws.Range("C12:C" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("D12").Value = ws.Range("I5").Value
ws.Range("D12:D" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("E12").Value = ws.Range("I4").Value
ws.Range("E12:E" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("F12").Value = ws.Range("I6").Value
ws.Range("F12:F" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

ws.Range("G12").Value = ws.Range("I7").Value
ws.Range("G12:G" & Cells(Rows.Count, 7).End(xlUp).Row).FillDown

Next ws

End Sub


I did a step by step, and the result is that the cell is copied in the first cell of the filldown range cells but then it's deleted. Can somebody help ?







excel vba copying






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 15:28









MrRarriMrRarri

305




305












  • In Cells(Rows.Count, 7).End(xlUp).Row you need to specify the worksheet: ws.Cells(ws.Rows.Count, 7).End(xlUp).Row Also note that 7 means column G. Check if that is the correct column to look for the last used row.

    – Pᴇʜ
    Nov 15 '18 at 15:39












  • Yeah, I tested that but I think Excel understands the reference between the Range() as it doesn't change anything if I put the sheet specification or not. Still have the same issue! The rows are all equal, the "7" was random, just in case I delete things while formatting my sheets :p

    – MrRarri
    Nov 15 '18 at 15:44


















  • In Cells(Rows.Count, 7).End(xlUp).Row you need to specify the worksheet: ws.Cells(ws.Rows.Count, 7).End(xlUp).Row Also note that 7 means column G. Check if that is the correct column to look for the last used row.

    – Pᴇʜ
    Nov 15 '18 at 15:39












  • Yeah, I tested that but I think Excel understands the reference between the Range() as it doesn't change anything if I put the sheet specification or not. Still have the same issue! The rows are all equal, the "7" was random, just in case I delete things while formatting my sheets :p

    – MrRarri
    Nov 15 '18 at 15:44

















In Cells(Rows.Count, 7).End(xlUp).Row you need to specify the worksheet: ws.Cells(ws.Rows.Count, 7).End(xlUp).Row Also note that 7 means column G. Check if that is the correct column to look for the last used row.

– Pᴇʜ
Nov 15 '18 at 15:39






In Cells(Rows.Count, 7).End(xlUp).Row you need to specify the worksheet: ws.Cells(ws.Rows.Count, 7).End(xlUp).Row Also note that 7 means column G. Check if that is the correct column to look for the last used row.

– Pᴇʜ
Nov 15 '18 at 15:39














Yeah, I tested that but I think Excel understands the reference between the Range() as it doesn't change anything if I put the sheet specification or not. Still have the same issue! The rows are all equal, the "7" was random, just in case I delete things while formatting my sheets :p

– MrRarri
Nov 15 '18 at 15:44






Yeah, I tested that but I think Excel understands the reference between the Range() as it doesn't change anything if I put the sheet specification or not. Still have the same issue! The rows are all equal, the "7" was random, just in case I delete things while formatting my sheets :p

– MrRarri
Nov 15 '18 at 15:44













1 Answer
1






active

oldest

votes


















1














The issue …



… is that you look for the last used row in column G



Cells(Rows.Count, 7).End(xlUp).Row


But since you added 6 columns with ws.[A1].Resize(, 6).EntireColumn.Insert column G is now empty, so the last used row is 1



and you actually run



ws.Range("A12:A1").FillDown


which takes the empty cell from A1 and fills it down until A12 (so your inserted value in A12 gets removed).




Solution



After inserting your original column G moved to



ws.Cells(ws.Rows.Count, 7 + 6).End(xlUp).Row





share|improve this answer




















  • 1





    Just realized what you were explaining. Thank you very much it works now. I will specify my worksheets as well! Thank you for the advice.

    – MrRarri
    Nov 15 '18 at 15:56











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%2f53322710%2ffilldown-columns-from-cells-value-in-each-worksheet%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The issue …



… is that you look for the last used row in column G



Cells(Rows.Count, 7).End(xlUp).Row


But since you added 6 columns with ws.[A1].Resize(, 6).EntireColumn.Insert column G is now empty, so the last used row is 1



and you actually run



ws.Range("A12:A1").FillDown


which takes the empty cell from A1 and fills it down until A12 (so your inserted value in A12 gets removed).




Solution



After inserting your original column G moved to



ws.Cells(ws.Rows.Count, 7 + 6).End(xlUp).Row





share|improve this answer




















  • 1





    Just realized what you were explaining. Thank you very much it works now. I will specify my worksheets as well! Thank you for the advice.

    – MrRarri
    Nov 15 '18 at 15:56















1














The issue …



… is that you look for the last used row in column G



Cells(Rows.Count, 7).End(xlUp).Row


But since you added 6 columns with ws.[A1].Resize(, 6).EntireColumn.Insert column G is now empty, so the last used row is 1



and you actually run



ws.Range("A12:A1").FillDown


which takes the empty cell from A1 and fills it down until A12 (so your inserted value in A12 gets removed).




Solution



After inserting your original column G moved to



ws.Cells(ws.Rows.Count, 7 + 6).End(xlUp).Row





share|improve this answer




















  • 1





    Just realized what you were explaining. Thank you very much it works now. I will specify my worksheets as well! Thank you for the advice.

    – MrRarri
    Nov 15 '18 at 15:56













1












1








1







The issue …



… is that you look for the last used row in column G



Cells(Rows.Count, 7).End(xlUp).Row


But since you added 6 columns with ws.[A1].Resize(, 6).EntireColumn.Insert column G is now empty, so the last used row is 1



and you actually run



ws.Range("A12:A1").FillDown


which takes the empty cell from A1 and fills it down until A12 (so your inserted value in A12 gets removed).




Solution



After inserting your original column G moved to



ws.Cells(ws.Rows.Count, 7 + 6).End(xlUp).Row





share|improve this answer















The issue …



… is that you look for the last used row in column G



Cells(Rows.Count, 7).End(xlUp).Row


But since you added 6 columns with ws.[A1].Resize(, 6).EntireColumn.Insert column G is now empty, so the last used row is 1



and you actually run



ws.Range("A12:A1").FillDown


which takes the empty cell from A1 and fills it down until A12 (so your inserted value in A12 gets removed).




Solution



After inserting your original column G moved to



ws.Cells(ws.Rows.Count, 7 + 6).End(xlUp).Row






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 16:00

























answered Nov 15 '18 at 15:53









PᴇʜPᴇʜ

25.3k63052




25.3k63052







  • 1





    Just realized what you were explaining. Thank you very much it works now. I will specify my worksheets as well! Thank you for the advice.

    – MrRarri
    Nov 15 '18 at 15:56












  • 1





    Just realized what you were explaining. Thank you very much it works now. I will specify my worksheets as well! Thank you for the advice.

    – MrRarri
    Nov 15 '18 at 15:56







1




1





Just realized what you were explaining. Thank you very much it works now. I will specify my worksheets as well! Thank you for the advice.

– MrRarri
Nov 15 '18 at 15:56





Just realized what you were explaining. Thank you very much it works now. I will specify my worksheets as well! Thank you for the advice.

– MrRarri
Nov 15 '18 at 15:56



















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%2f53322710%2ffilldown-columns-from-cells-value-in-each-worksheet%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

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo