Paste (dynamic) lookup formula in dynamic number of columns
I have a sheet "2018" and "2019" which i created previously. 2019 only differs from 2018 in that it may have some rows added and/or some deleted.
Form Cell "A3" and downwards i have skills listed and a "X" in the columns after if the person the column belongs to has this skill.
Now i need to fill the columns of 2019 with known X with formula below, first a bit of context code for the range selection part:
Dim rng As Range
Dim rngbegin As Range
Dim rngend As Range
Dim newrng As Range
Sheets("2018").Activate
Set rng = Application.InputBox '...and rest of the code
rng.Copy
Sheets("2019").Range("B:B").Insert Shift:=xlToRight
Sheets(2019).Activate
Set rngbegin = rng.Cells(3, 1)
Set rngend = rng.Cells(3000, rng.Columns.Count)
Set newrng = Range(rngbegin.Address & ":" & rngend.Address)
newrng.ClearContents 'To clear everything in the difined range but the headder rows
Here is a formula i could use if the columns wouldn't be varying.
Range("B3").Select
ActiveCell.Formula = "=IFERROR(LOOKUP(2,1/($A3='2018'!$A$3:D$5000),'2018'!$B$3:$B$5000),"")"
Range("B2").AutoFill Destination:=Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
The Formula works but i have the following problems:
1 - Required) I can't hardcode the formula for every column because the number of colums may change. (I store the number of columns as range var selected from the user via application.inputbox - that's how i inserted the colums in the new 2019 sheet)
2 - optional) I hardcoded the rows to a much higher number than are used because i didn't thnk of counting Column A and then use the range.count.Address(?) as end of the search vector. Just came into my mind lol
excel vba excel-vba
add a comment |
I have a sheet "2018" and "2019" which i created previously. 2019 only differs from 2018 in that it may have some rows added and/or some deleted.
Form Cell "A3" and downwards i have skills listed and a "X" in the columns after if the person the column belongs to has this skill.
Now i need to fill the columns of 2019 with known X with formula below, first a bit of context code for the range selection part:
Dim rng As Range
Dim rngbegin As Range
Dim rngend As Range
Dim newrng As Range
Sheets("2018").Activate
Set rng = Application.InputBox '...and rest of the code
rng.Copy
Sheets("2019").Range("B:B").Insert Shift:=xlToRight
Sheets(2019).Activate
Set rngbegin = rng.Cells(3, 1)
Set rngend = rng.Cells(3000, rng.Columns.Count)
Set newrng = Range(rngbegin.Address & ":" & rngend.Address)
newrng.ClearContents 'To clear everything in the difined range but the headder rows
Here is a formula i could use if the columns wouldn't be varying.
Range("B3").Select
ActiveCell.Formula = "=IFERROR(LOOKUP(2,1/($A3='2018'!$A$3:D$5000),'2018'!$B$3:$B$5000),"")"
Range("B2").AutoFill Destination:=Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
The Formula works but i have the following problems:
1 - Required) I can't hardcode the formula for every column because the number of colums may change. (I store the number of columns as range var selected from the user via application.inputbox - that's how i inserted the colums in the new 2019 sheet)
2 - optional) I hardcoded the rows to a much higher number than are used because i didn't thnk of counting Column A and then use the range.count.Address(?) as end of the search vector. Just came into my mind lol
excel vba excel-vba
What arerng1
andrng2
here?
– Tim Williams
Nov 11 '18 at 23:43
Sorry forgot to change variables.Corrected.
– Matthias94
Nov 11 '18 at 23:45
Steer clear from.Activate
makes your code run slow. To clear contents simply useSheets("2019").Rows("3:" & Rows.Count).EntireRow.ClearContents
– alowflyingpig
Nov 12 '18 at 0:50
To find the last used column in row 1 tryCells(1, Columns.Count).End(xlToLeft).Column
– alowflyingpig
Nov 12 '18 at 0:56
With your code i would clear the whole rows from 3 downwards, but with my code i copy columns with contents (X's). While i need the headers, i don't need the filled out X because they are false if simply copied (row contents of Column "A" may have changed.) so i saw no other way than to create a new range out of the user selected range (Column:Column)
– Matthias94
Nov 12 '18 at 7:47
add a comment |
I have a sheet "2018" and "2019" which i created previously. 2019 only differs from 2018 in that it may have some rows added and/or some deleted.
Form Cell "A3" and downwards i have skills listed and a "X" in the columns after if the person the column belongs to has this skill.
Now i need to fill the columns of 2019 with known X with formula below, first a bit of context code for the range selection part:
Dim rng As Range
Dim rngbegin As Range
Dim rngend As Range
Dim newrng As Range
Sheets("2018").Activate
Set rng = Application.InputBox '...and rest of the code
rng.Copy
Sheets("2019").Range("B:B").Insert Shift:=xlToRight
Sheets(2019).Activate
Set rngbegin = rng.Cells(3, 1)
Set rngend = rng.Cells(3000, rng.Columns.Count)
Set newrng = Range(rngbegin.Address & ":" & rngend.Address)
newrng.ClearContents 'To clear everything in the difined range but the headder rows
Here is a formula i could use if the columns wouldn't be varying.
Range("B3").Select
ActiveCell.Formula = "=IFERROR(LOOKUP(2,1/($A3='2018'!$A$3:D$5000),'2018'!$B$3:$B$5000),"")"
Range("B2").AutoFill Destination:=Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
The Formula works but i have the following problems:
1 - Required) I can't hardcode the formula for every column because the number of colums may change. (I store the number of columns as range var selected from the user via application.inputbox - that's how i inserted the colums in the new 2019 sheet)
2 - optional) I hardcoded the rows to a much higher number than are used because i didn't thnk of counting Column A and then use the range.count.Address(?) as end of the search vector. Just came into my mind lol
excel vba excel-vba
I have a sheet "2018" and "2019" which i created previously. 2019 only differs from 2018 in that it may have some rows added and/or some deleted.
Form Cell "A3" and downwards i have skills listed and a "X" in the columns after if the person the column belongs to has this skill.
Now i need to fill the columns of 2019 with known X with formula below, first a bit of context code for the range selection part:
Dim rng As Range
Dim rngbegin As Range
Dim rngend As Range
Dim newrng As Range
Sheets("2018").Activate
Set rng = Application.InputBox '...and rest of the code
rng.Copy
Sheets("2019").Range("B:B").Insert Shift:=xlToRight
Sheets(2019).Activate
Set rngbegin = rng.Cells(3, 1)
Set rngend = rng.Cells(3000, rng.Columns.Count)
Set newrng = Range(rngbegin.Address & ":" & rngend.Address)
newrng.ClearContents 'To clear everything in the difined range but the headder rows
Here is a formula i could use if the columns wouldn't be varying.
Range("B3").Select
ActiveCell.Formula = "=IFERROR(LOOKUP(2,1/($A3='2018'!$A$3:D$5000),'2018'!$B$3:$B$5000),"")"
Range("B2").AutoFill Destination:=Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
The Formula works but i have the following problems:
1 - Required) I can't hardcode the formula for every column because the number of colums may change. (I store the number of columns as range var selected from the user via application.inputbox - that's how i inserted the colums in the new 2019 sheet)
2 - optional) I hardcoded the rows to a much higher number than are used because i didn't thnk of counting Column A and then use the range.count.Address(?) as end of the search vector. Just came into my mind lol
excel vba excel-vba
excel vba excel-vba
edited Nov 11 '18 at 23:44
asked Nov 11 '18 at 23:38
Matthias94
275
275
What arerng1
andrng2
here?
– Tim Williams
Nov 11 '18 at 23:43
Sorry forgot to change variables.Corrected.
– Matthias94
Nov 11 '18 at 23:45
Steer clear from.Activate
makes your code run slow. To clear contents simply useSheets("2019").Rows("3:" & Rows.Count).EntireRow.ClearContents
– alowflyingpig
Nov 12 '18 at 0:50
To find the last used column in row 1 tryCells(1, Columns.Count).End(xlToLeft).Column
– alowflyingpig
Nov 12 '18 at 0:56
With your code i would clear the whole rows from 3 downwards, but with my code i copy columns with contents (X's). While i need the headers, i don't need the filled out X because they are false if simply copied (row contents of Column "A" may have changed.) so i saw no other way than to create a new range out of the user selected range (Column:Column)
– Matthias94
Nov 12 '18 at 7:47
add a comment |
What arerng1
andrng2
here?
– Tim Williams
Nov 11 '18 at 23:43
Sorry forgot to change variables.Corrected.
– Matthias94
Nov 11 '18 at 23:45
Steer clear from.Activate
makes your code run slow. To clear contents simply useSheets("2019").Rows("3:" & Rows.Count).EntireRow.ClearContents
– alowflyingpig
Nov 12 '18 at 0:50
To find the last used column in row 1 tryCells(1, Columns.Count).End(xlToLeft).Column
– alowflyingpig
Nov 12 '18 at 0:56
With your code i would clear the whole rows from 3 downwards, but with my code i copy columns with contents (X's). While i need the headers, i don't need the filled out X because they are false if simply copied (row contents of Column "A" may have changed.) so i saw no other way than to create a new range out of the user selected range (Column:Column)
– Matthias94
Nov 12 '18 at 7:47
What are
rng1
and rng2
here?– Tim Williams
Nov 11 '18 at 23:43
What are
rng1
and rng2
here?– Tim Williams
Nov 11 '18 at 23:43
Sorry forgot to change variables.Corrected.
– Matthias94
Nov 11 '18 at 23:45
Sorry forgot to change variables.Corrected.
– Matthias94
Nov 11 '18 at 23:45
Steer clear from
.Activate
makes your code run slow. To clear contents simply use Sheets("2019").Rows("3:" & Rows.Count).EntireRow.ClearContents
– alowflyingpig
Nov 12 '18 at 0:50
Steer clear from
.Activate
makes your code run slow. To clear contents simply use Sheets("2019").Rows("3:" & Rows.Count).EntireRow.ClearContents
– alowflyingpig
Nov 12 '18 at 0:50
To find the last used column in row 1 try
Cells(1, Columns.Count).End(xlToLeft).Column
– alowflyingpig
Nov 12 '18 at 0:56
To find the last used column in row 1 try
Cells(1, Columns.Count).End(xlToLeft).Column
– alowflyingpig
Nov 12 '18 at 0:56
With your code i would clear the whole rows from 3 downwards, but with my code i copy columns with contents (X's). While i need the headers, i don't need the filled out X because they are false if simply copied (row contents of Column "A" may have changed.) so i saw no other way than to create a new range out of the user selected range (Column:Column)
– Matthias94
Nov 12 '18 at 7:47
With your code i would clear the whole rows from 3 downwards, but with my code i copy columns with contents (X's). While i need the headers, i don't need the filled out X because they are false if simply copied (row contents of Column "A" may have changed.) so i saw no other way than to create a new range out of the user selected range (Column:Column)
– Matthias94
Nov 12 '18 at 7:47
add a comment |
1 Answer
1
active
oldest
votes
You will probably need to tweak a few addresses. I left much of your code unchanged so you can easily adapt what I have came up with for your purposes.
Sub Whatever()
With Sheets("2018")
' Get the address of the old range, not used later in the macro
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(3, Columns.Count).End(xlToLeft).Column
Set rngOld = Range(.Cells(3, 2), .Cells(iRows, iCols))
End With
With Sheets("2019")
' Get the address of the new range
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(2, Columns.Count).End(xlToLeft).Column
Set rngNew = Range(.Cells(3, 2), .Cells(iRows, iCols))
'Clear the new range
rngNew.Clear
' Populate the formula
' Not very elegant, VBA solution would probably look nicer
.Range("B3").Formula = "=IFERROR(if(LOOKUP(2,1/('2018'!$A$3:$A$" & iRows & " =$A3),'2018'!B$3:B$" & iRows & ")=""X"",""X"",""""),"""")"
'Fill the formula
Set rngTemp = .Range(.Cells(3, 2), .Cells(3, iCols))
rngTemp.FillRight
Set rngTemp = .Range(.Cells(3, 2), .Cells(iRows, iCols))
rngTemp.FillDown
End With
End Sub
Hello Michal, unfortunately your solution deletes whole rows and not the user defined range + all the way down. Same with formula. I created a screenshot to show my needs: picload.org/view/dcolclcg/problemstellung.png.html
– Matthias94
Nov 13 '18 at 8:16
As I said in my original post - you will possibly need to tweak a few addresses to make it work. You have already done a lot of good work, might as well try to finish it by yourself :) Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:36
I tweaked the cells addresses in the above and it works as requested. Cheers,
– Michal Rosa
Nov 13 '18 at 8:42
Okay, i'll try it :)
– Matthias94
Nov 13 '18 at 8:42
1
Minor edit to make it perfect.. hope it works for you. Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:54
|
show 4 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254346%2fpaste-dynamic-lookup-formula-in-dynamic-number-of-columns%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
You will probably need to tweak a few addresses. I left much of your code unchanged so you can easily adapt what I have came up with for your purposes.
Sub Whatever()
With Sheets("2018")
' Get the address of the old range, not used later in the macro
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(3, Columns.Count).End(xlToLeft).Column
Set rngOld = Range(.Cells(3, 2), .Cells(iRows, iCols))
End With
With Sheets("2019")
' Get the address of the new range
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(2, Columns.Count).End(xlToLeft).Column
Set rngNew = Range(.Cells(3, 2), .Cells(iRows, iCols))
'Clear the new range
rngNew.Clear
' Populate the formula
' Not very elegant, VBA solution would probably look nicer
.Range("B3").Formula = "=IFERROR(if(LOOKUP(2,1/('2018'!$A$3:$A$" & iRows & " =$A3),'2018'!B$3:B$" & iRows & ")=""X"",""X"",""""),"""")"
'Fill the formula
Set rngTemp = .Range(.Cells(3, 2), .Cells(3, iCols))
rngTemp.FillRight
Set rngTemp = .Range(.Cells(3, 2), .Cells(iRows, iCols))
rngTemp.FillDown
End With
End Sub
Hello Michal, unfortunately your solution deletes whole rows and not the user defined range + all the way down. Same with formula. I created a screenshot to show my needs: picload.org/view/dcolclcg/problemstellung.png.html
– Matthias94
Nov 13 '18 at 8:16
As I said in my original post - you will possibly need to tweak a few addresses to make it work. You have already done a lot of good work, might as well try to finish it by yourself :) Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:36
I tweaked the cells addresses in the above and it works as requested. Cheers,
– Michal Rosa
Nov 13 '18 at 8:42
Okay, i'll try it :)
– Matthias94
Nov 13 '18 at 8:42
1
Minor edit to make it perfect.. hope it works for you. Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:54
|
show 4 more comments
You will probably need to tweak a few addresses. I left much of your code unchanged so you can easily adapt what I have came up with for your purposes.
Sub Whatever()
With Sheets("2018")
' Get the address of the old range, not used later in the macro
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(3, Columns.Count).End(xlToLeft).Column
Set rngOld = Range(.Cells(3, 2), .Cells(iRows, iCols))
End With
With Sheets("2019")
' Get the address of the new range
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(2, Columns.Count).End(xlToLeft).Column
Set rngNew = Range(.Cells(3, 2), .Cells(iRows, iCols))
'Clear the new range
rngNew.Clear
' Populate the formula
' Not very elegant, VBA solution would probably look nicer
.Range("B3").Formula = "=IFERROR(if(LOOKUP(2,1/('2018'!$A$3:$A$" & iRows & " =$A3),'2018'!B$3:B$" & iRows & ")=""X"",""X"",""""),"""")"
'Fill the formula
Set rngTemp = .Range(.Cells(3, 2), .Cells(3, iCols))
rngTemp.FillRight
Set rngTemp = .Range(.Cells(3, 2), .Cells(iRows, iCols))
rngTemp.FillDown
End With
End Sub
Hello Michal, unfortunately your solution deletes whole rows and not the user defined range + all the way down. Same with formula. I created a screenshot to show my needs: picload.org/view/dcolclcg/problemstellung.png.html
– Matthias94
Nov 13 '18 at 8:16
As I said in my original post - you will possibly need to tweak a few addresses to make it work. You have already done a lot of good work, might as well try to finish it by yourself :) Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:36
I tweaked the cells addresses in the above and it works as requested. Cheers,
– Michal Rosa
Nov 13 '18 at 8:42
Okay, i'll try it :)
– Matthias94
Nov 13 '18 at 8:42
1
Minor edit to make it perfect.. hope it works for you. Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:54
|
show 4 more comments
You will probably need to tweak a few addresses. I left much of your code unchanged so you can easily adapt what I have came up with for your purposes.
Sub Whatever()
With Sheets("2018")
' Get the address of the old range, not used later in the macro
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(3, Columns.Count).End(xlToLeft).Column
Set rngOld = Range(.Cells(3, 2), .Cells(iRows, iCols))
End With
With Sheets("2019")
' Get the address of the new range
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(2, Columns.Count).End(xlToLeft).Column
Set rngNew = Range(.Cells(3, 2), .Cells(iRows, iCols))
'Clear the new range
rngNew.Clear
' Populate the formula
' Not very elegant, VBA solution would probably look nicer
.Range("B3").Formula = "=IFERROR(if(LOOKUP(2,1/('2018'!$A$3:$A$" & iRows & " =$A3),'2018'!B$3:B$" & iRows & ")=""X"",""X"",""""),"""")"
'Fill the formula
Set rngTemp = .Range(.Cells(3, 2), .Cells(3, iCols))
rngTemp.FillRight
Set rngTemp = .Range(.Cells(3, 2), .Cells(iRows, iCols))
rngTemp.FillDown
End With
End Sub
You will probably need to tweak a few addresses. I left much of your code unchanged so you can easily adapt what I have came up with for your purposes.
Sub Whatever()
With Sheets("2018")
' Get the address of the old range, not used later in the macro
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(3, Columns.Count).End(xlToLeft).Column
Set rngOld = Range(.Cells(3, 2), .Cells(iRows, iCols))
End With
With Sheets("2019")
' Get the address of the new range
iRows = .Cells(Rows.Count, 1).End(xlUp).Row
iCols = .Cells(2, Columns.Count).End(xlToLeft).Column
Set rngNew = Range(.Cells(3, 2), .Cells(iRows, iCols))
'Clear the new range
rngNew.Clear
' Populate the formula
' Not very elegant, VBA solution would probably look nicer
.Range("B3").Formula = "=IFERROR(if(LOOKUP(2,1/('2018'!$A$3:$A$" & iRows & " =$A3),'2018'!B$3:B$" & iRows & ")=""X"",""X"",""""),"""")"
'Fill the formula
Set rngTemp = .Range(.Cells(3, 2), .Cells(3, iCols))
rngTemp.FillRight
Set rngTemp = .Range(.Cells(3, 2), .Cells(iRows, iCols))
rngTemp.FillDown
End With
End Sub
edited Nov 13 '18 at 8:53
answered Nov 12 '18 at 5:52
Michal Rosa
1,3061814
1,3061814
Hello Michal, unfortunately your solution deletes whole rows and not the user defined range + all the way down. Same with formula. I created a screenshot to show my needs: picload.org/view/dcolclcg/problemstellung.png.html
– Matthias94
Nov 13 '18 at 8:16
As I said in my original post - you will possibly need to tweak a few addresses to make it work. You have already done a lot of good work, might as well try to finish it by yourself :) Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:36
I tweaked the cells addresses in the above and it works as requested. Cheers,
– Michal Rosa
Nov 13 '18 at 8:42
Okay, i'll try it :)
– Matthias94
Nov 13 '18 at 8:42
1
Minor edit to make it perfect.. hope it works for you. Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:54
|
show 4 more comments
Hello Michal, unfortunately your solution deletes whole rows and not the user defined range + all the way down. Same with formula. I created a screenshot to show my needs: picload.org/view/dcolclcg/problemstellung.png.html
– Matthias94
Nov 13 '18 at 8:16
As I said in my original post - you will possibly need to tweak a few addresses to make it work. You have already done a lot of good work, might as well try to finish it by yourself :) Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:36
I tweaked the cells addresses in the above and it works as requested. Cheers,
– Michal Rosa
Nov 13 '18 at 8:42
Okay, i'll try it :)
– Matthias94
Nov 13 '18 at 8:42
1
Minor edit to make it perfect.. hope it works for you. Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:54
Hello Michal, unfortunately your solution deletes whole rows and not the user defined range + all the way down. Same with formula. I created a screenshot to show my needs: picload.org/view/dcolclcg/problemstellung.png.html
– Matthias94
Nov 13 '18 at 8:16
Hello Michal, unfortunately your solution deletes whole rows and not the user defined range + all the way down. Same with formula. I created a screenshot to show my needs: picload.org/view/dcolclcg/problemstellung.png.html
– Matthias94
Nov 13 '18 at 8:16
As I said in my original post - you will possibly need to tweak a few addresses to make it work. You have already done a lot of good work, might as well try to finish it by yourself :) Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:36
As I said in my original post - you will possibly need to tweak a few addresses to make it work. You have already done a lot of good work, might as well try to finish it by yourself :) Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:36
I tweaked the cells addresses in the above and it works as requested. Cheers,
– Michal Rosa
Nov 13 '18 at 8:42
I tweaked the cells addresses in the above and it works as requested. Cheers,
– Michal Rosa
Nov 13 '18 at 8:42
Okay, i'll try it :)
– Matthias94
Nov 13 '18 at 8:42
Okay, i'll try it :)
– Matthias94
Nov 13 '18 at 8:42
1
1
Minor edit to make it perfect.. hope it works for you. Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:54
Minor edit to make it perfect.. hope it works for you. Cheers, Michal
– Michal Rosa
Nov 13 '18 at 8:54
|
show 4 more comments
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254346%2fpaste-dynamic-lookup-formula-in-dynamic-number-of-columns%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What are
rng1
andrng2
here?– Tim Williams
Nov 11 '18 at 23:43
Sorry forgot to change variables.Corrected.
– Matthias94
Nov 11 '18 at 23:45
Steer clear from
.Activate
makes your code run slow. To clear contents simply useSheets("2019").Rows("3:" & Rows.Count).EntireRow.ClearContents
– alowflyingpig
Nov 12 '18 at 0:50
To find the last used column in row 1 try
Cells(1, Columns.Count).End(xlToLeft).Column
– alowflyingpig
Nov 12 '18 at 0:56
With your code i would clear the whole rows from 3 downwards, but with my code i copy columns with contents (X's). While i need the headers, i don't need the filled out X because they are false if simply copied (row contents of Column "A" may have changed.) so i saw no other way than to create a new range out of the user selected range (Column:Column)
– Matthias94
Nov 12 '18 at 7:47