Reputation: 149
I keep coming across this code when searching for a way to copy a row based on a value in a column. The issue I'm running into is that I am not using the same phrase every single time I want to run the table. I'd like it to change what it copies based on what is in cell B18 versus using the same value every time. I linked the macro that I've been seeing above, but the specific lines of code are:
If Range("E" & CStr(LSearchRow)).Value = "Mail Box" Then
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
Instead of "Mail Box" I'd like to use the contents of cell B18 on sheet "Dashboard"
Any help would be appreciated!
Upvotes: 1
Views: 69
Reputation: 23081
Try this. Note that Select
not needed. You should really add a sheet reference to the first range too and the Rows
.
If Range("E" & CStr(LSearchRow)).Value = sheets("Dashboard").Range("B18").Value Then
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Copy
Upvotes: 2