Hey all. Hope all is good.
I am a beginner in VBA and the below written one is my first code and I need some clarification from you guys. This question seems to be simple for you guys but actually I don't know how to consolidate it. And also, I don't even know whether its properly structured or not. But its working fine.
I have just shown the Vlookup part in the below code. But actually this has a lot of nested if conditions and this code has approximately 25 lines of the similar type.
My question is:
1) I have used Range("A2") & Resize(9, 1) command in all the lines.
Is there any option where I can use it only once in the beginning itself instead of writing it in all the lines. Range("A2") & Resize(9, 1) is same for all the lines.
2) In every excel workbook, only Range("A2") & Resize(9, 1) values will be varying. The rest of the commands / values will be same. Is there any option where I can save / run this code as a new feature in excel and when I run, it has to ask for entering the Range & Resize.
VBA code:
Sub Macro1()
'
' Macro1 Macro
'
'
Range("A2").Offset(0, 1).Resize(9, 1) = "=VLOOKUP(RC[-1],Database.xlsx!R1C1:R300C24,6,0)"
Range("A2").Offset(0, 4).Resize(9, 1) = "=VLOOKUP(RC[-4],Database.xlsx!R1C1:R300C24,15,0)"
Range("A2").Offset(0, 2).Resize(9, 1) = "=VLOOKUP(RC[-2],Database.xlsx!R1C1:R300C24,10,0)"
Range("A2").Offset(0, 3).Resize(9, 1) = "=VLOOKUP(RC[-3],Database.xlsx!R1C1:R300C24,13,0)"
Range("A2").Offset(0, 5).Resize(9, 1) = "=VLOOKUP(RC[-5],Database.xlsx!R1C1:R300C24,19,0)"
Range("A2").Offset(0, 6).Resize(9, 1) = "=VLOOKUP(RC[-6],Database.xlsx!R1C1:R300C24,22,0)"
End Sub
Thanks in advance for your time & suggestion.
Bookmarks