Reputation: 69
I am trying to write a copy/paste as values macro that involves a drop down menu. I think I have the "drop down" part, but I need Excel to copy/paste as values one row at a time before plugging in the next drop down value.
What I need help figuring out is do I have the 1)"d8 = d" in the right order, should it be moved up 2) is the syntax for the copy/paste range correct?
3) how do I tell it to Copy/paste as values one row at a time?
Here is the sheet with the cells I want to copy/paste as values
Will this code give me what I want in terms of plugging in the dropdown, letting the formulas calc, and the copying and pasting one line at a time?
Sub Copy_Paste()
Sheets("MS Wall Summary Weekly View").Activate
Dim vRws As Long, vRng As Range
Dim d As Range, d8 As Range, Wst As Worksheet
Dim vRng2 As Range, vRws2 As Long, i As Long
Set Wst = Worksheets("MS Wall Summary Weekly View")
Set d8 = Wst.Range("D8")
With Wst
vRws = .Cells(.Rows.Count, "A").End(xlUp).Row
Set vRng = Range(.Cells(2, "A"), .Cells(vRws, "A"))
End With
For Each d In vRng.Cells
d8 = d
Sheets("Email").Activate
With ActiveSheet
vRws2 = .Cells(.Rows.Count, "U").End(x1Up).Row
For i = 8 To vRws2
Set vRng2 = Range("U" & i & "AC" & i)
vRng2.Copy
vRng2.PasteSpecial Paste:=xlPasteValues
End With
Next d
Next i
Upvotes: 0
Views: 33
Reputation: 14580
The nice thing about compile errors is that they tell you exactly where the error exists. You had typos and a invalid string build on the marked lines below
...End(x1Up)
(you swapped the number 1 with letter l). Set vRng2 = Range (""U" & i:"AC"& i")
. You have double quotes around the U
and you did not enclose the :
inside quotes. You also left i
inside the quotes. Please see correct method in code belowOption Explicit
Sub Copy_Paste()
Sheets("MS Wall Summary Weekly View").Activate
Dim vRws As Long, vRng As Range
Dim d As Range, d8 As Range, Wst As Worksheet
Dim vRng2 As Range, vRws2 As Long, i As Long
Set Wst = Worksheets("MS Wall Summary Weekly View")
Set d8 = Wst.Range("D8")
With Wst
vRws = .Cells(.Rows.Count, "A").End(xlUp).Row
Set vRng = .Range(.Cells(2, "A"), .Cells(vRws, "A"))
End With
For Each d In vRng.Cells
d8 = d
Sheets("Email").Activate
With ActiveSheet
vRws2 = .Cells(.Rows.Count, "U").End(xlUp).Row '< -- Here
For i = 8 To vRws2
Set vRng2 = .Range("U" & i & "AC" & i) '< -- Here
Next d
A couple of other issues at a glance
MS Wall Summary Weekly View
sheet variable right away and remove the .Activate
line at the startWith
block all the way. Your Range
properties need to be prefixed with a dotd8
as a range but you set it equal to d
. You may need to revisit what the goal is here as this is not a valid rangeCells
property (On Error 2: above). You can use .Range(.Cells(i, "U"), .Cells(i, "AC"))
instead (note the qualifier dot, going against the With ActiveSheet
block variable)Upvotes: 2