FIlling in a Vlookup on dynamic range and multiple columns

March 20, 2019 at 14:28:17
Specs: Macintosh
Hi guys,

Can you please share with me what I am doing wrong on my code? My data ranges change each time I run the process so I want to make sure I get them all. Here is what I have currently:

"Sub Step18()
'
' Step18 Macro
'

'
Sheets("Contact").Select
Range("P1").Select
ActiveCell.FormulaR1C1 = "VlookupType"
Range("Q1").Select
ActiveCell.FormulaR1C1 = "VlookupIP"
Range("R1").Select
ActiveCell.FormulaR1C1 = "VlookupMailingName"
Range("P2").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-15],PastedValues!C[-15]:C[-12],2,FALSE)"
Selection.AutoFill Destination:=Range("P2:P & LastRow")
Range("P2:P").Select
Range("Q2").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-16],PastedValues!C[-16]:C[-13],4,FALSE)"
Selection.AutoFill Destination:=Range("Q:Q")
Range("Q2:Q").Select
Range("R2").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
Sheets("ContactDetailed").Select
Rows("1:1").Select
ActiveSheet.ShowAllData
Sheets("Contact").Select
Range("R2").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-17],ContactDetailed!C[-17]:C[-14],4,FALSE)"
Selection.AutoFill Destination:=Range("R2:R")
Range("R2:R").Select
End Sub"


See More: FIlling in a Vlookup on dynamic range and multiple columns

Reply ↓  Report •

#1
March 20, 2019 at 15:01:57
Please click on the How-To link at the end of this post and read the instructions on how to post VBA code in this forum. Then please edit/repost your code based on those instructions.

Before we start looking over your code, I'd like to ask a question. It's OK if the answer is No, I'm only trying to gauge your level of VBA expertise.

Do you know how to edit VBA code?

The reason I ask is that the code you posted appears to be have been recorded. All those extra .Select instructions that don't appear to serve any purpose and the repetitious CutCopyMode instructions indicate to me that this code was not hand written.

It would make our lives a lot easier if all of those extraneous instructions were deleted so we could get down to the meat of the code and offer some assistance. Again, if you don't know how to make those changes, i.e. you don't know what is important and what isn't, that's OK. Just let us know that.

Finally, please keep in mind that we can't see your workbook from where we are sitting nor do we know anything about your work process. You don't really explain what you mean by "doing wrong with my code" and we don't know what "get them all" means.

Before we can offer any assistance, I think we need a deeper understand of what the code is supposed to be doing.

How To Post Data or Code ---> Click Here Before Posting Data or VBA Code


Reply ↓  Report •
Related Solutions


Ask Question