Macros code to insert rectangle, Macros ode to Concatenate, Macros code for Dynamic Vlookup, Macros code for Last visible Cell, Count Cell, Visible Rows and Columns
4. Sub concatenate()
‘Applying Concatenate formula by using “range”
Range("a3").Value = Range("a1") & " " & Range("a2").Value
End Sub
CODE CONCATENATE
THANK YOU
Sub concatenate ()
‘Applying Concatenate formula by using “Cells”
Cells(3, 1).Value = Cells(1, 1) & " " & Cells(2, 1).Value
End Sub
OR
6. Dynamic Vlookup include 3 step:
1) Identifying Last Visible Cell till which Vlookup formula will run
2) Identifying the table range for Vlookup
3) Loop code to execute “Vlookup” formula till last visible cell
CODE FOR DYNAMIC VLOOKUP
NEXT: CODE FOR LAST VISIBLE CELL
7. 1: COUNT CELL
• It important to find count visible row cell so that when programme runs
“Vlookup Formula” it may known were to stop.
• Vlookup helps to find the value from Other workbook/sheets or from
same sheet with the help of unique reference and therefore reference is
important incase of it absence there will be an error.
• If we not find the last cell till which “Vlookup formula” should run, then it
may continue to run through out the sheet till the last cell of the sheet.
NEXT: COUNT VISIBLE ROW CELL
8. Sub Count_Visible_row()
'This code help to find only last visible row by counting all visible cell. But
it do not count last visible column
Dim Count_cell As Integer
Dim Row_Range As String
Sheet1.Select
Count_cell = WorksheetFunction.CountA(Range("A:A"))
End Sub
COUNT VISIBLE ROW CELL
NEXT: CODE FOR LAST VISIBLE ROW
CELL & RANGE
9. 2: TABLE_ARRAY OR TABLE RANGE
• Table Array or a Range from which value is to be looked should be
dynamic means, Range should include any new row/column or exclude
any newly deleted row/column automatically.
• To do that we need run a code before executing Vlookup formula, which
help to find the last Row Cell & Last Column Cell.
• Finding of Last Row & Column will helps to formulate a Table Array or
Range from which value is to be looked.
NEXT: CODE FOR LAST VISIBLE BOTH
ROW & COLUMN
10. Sub last_Visible_row()
' This code help to find only last visible row by counting all visible cell. But it
do not count last visible column
Dim Lastcell As String
Dim Row_Range As String
Lastcell = Range("a1").End(xlDown).Address
MsgBox (Lastcell)
Row_Range = Range("A1:" & Lastcell).Address
MsgBox (Row_Range)
End Sub
CODE FOR LAST VISIBLE ROW CELL & RANGE
NEXT: CODE FOR LAST VISIBLE COLUMN
CELL & RANGE
Code helps to find the
address of last cell in
Row
Code helps to find the
row’s range address
11. Sub last_Visible_column()
' This code help to find only last visible row by counting all visible cell. But it
do not count last visible column
Dim Lastcell As String
Dim Column_Range As String
Lastcell = Range("a1").End(xlToRight).Address
MsgBox (Lastcell)
Column_Range = Range("A1:" & Lastcell).Address
MsgBox (Column_Range)
End Sub
CODE FOR LAST VISIBLE COLUMN
CELL & RANGE
NEXT: CODE FOR LAST VISIBLE
ROW CELL & RANGE
Code helps to find the
address of last cell in
Column
Code helps to find the
column’s range address
12. Sub last_Visible_Row_Column()
'This code help to find only last visible row by counting all visible cell. But it
do not count last visible column
Dim Lastcell_Row As String
Dim Lastcell_Column As String
Dim Table_Range As String
Lastcell_Row = Range("a1").End(xlDown).Address
Lastcell_Column = Range("a1").End(xlToRight).Address
Table_Range = Range(Lastcell_Row & ":" & Lastcell_Column).Address
MsgBox (Table_Range)
End Sub
NEXT: CODE FOR LAST VISIBLE BOTH
ROW & COLUMN
NEXT: CODE FOR LAST VISIBLE BOTH
ROW & COLUMN
13. 3: LOOP FOR VLOOKUP
• Loop is use to perform same repetitive work.
• Loop can be customized by providing condition to it.
• Inserting Vlookup formula in each cell of row is an continuous process.
And therefore to perform such repetitive work Loop are used
NEXT: “FOR LOOP” FOR VLOOKUP
14. Sub Loop_for_Vlookup()
'Count the number cell in which Vlookup need to performed which can be done through last cell visible code
which we have done in previous slide.
Dim count_Cell As Integer 'Insert Count Cell code to count no. of Visible Rows for Vlookup
Dim Lastcell_Row As String 'Code to Identify last cell of row to form dynamic table array
Dim Lastcell_Column As String 'Code to Identify last cell of column to form dynamic table array
Dim Table_Range As String 'Code to combine result from Last cell Row and Last Cell Column
Dim reference As String 'code for reference of cell for which valued are looked up
For j = 1 To count_Cell
reference = ("$A" & j)
ActiveCell.Formula = "=VLOOKUP(" & reference & ",Sheet1!" & Table_Range & " ,2,0)"
ActiveCell.Offset(1, 0).Select
Next j
End Sub
“FOR LOOP” FOR VLOOKUP
NEXT: DYNAMIC VLOOKUP
15. DYNAMIC VLOOKUP
Sub Dynamic_Vlookup()
Dim count_Cell As Integer
Dim reference As String
Dim Lastcell_Row As String
Dim Lastcell_Column As String
Dim Table_Range As String
Sheet2.Select
count_Cell =
WorksheetFunction.CountA(Range("A:A"))
Sheet1.Select
Lastcell_Row =
Range("a1").End(xlDown).Address
Lastcell_Column =
Range("a1").End(xlToRight).Address
Table_Range = Range(Lastcell_Row & ":" &
Lastcell_Column).Address
MsgBox (Table_Range)
Sheet2.Select
Range("B1").Select
For j = 1 To count_Cell
reference = ("$A" & j)
ActiveCell.Formula = "=VLOOKUP(" & reference &
",Sheet1!" & Table_Range & " ,2,0)"
ActiveCell.Offset(1, 0).Select
Next j
End Sub