I have work book which has 2 sheets Sheet1(No,Host,date,String,ID,TKT) Data ( ID & Name )
I want to create a single Macro which can add column with name and vlookup iD in data sheet and return name and change the color using id column
What i have
I have 2 separate Macros 1- Macro to change the color using id column
Worksheet code
Sub ChangeColor()
lRow = Range("E" & Rows.Count).End(xlUp).Row
Set MR = Range("E2:E" & lRow)
For Each cell In MR
Select Case cell.Value
Case "x12340"
cell_colour = 2
Case "x12341"
cell_colour = 6
cell.EntireRow.Font.ColorIndex = 4
Case "x12342"
cell_colour=6
cell.EntireRow.Font.ColorIndex = 2
Case "x12343"
cell_colour=7
cell.EntireRow.Font.ColorIndex = 2
Case "x12344"
cell_colour=8
cell.EntireRow.Font.ColorIndex = 2
Case "x12345"
cell_colour=9
cell.EntireRow.Font.ColorIndex = 2
Case Else
cell_colour = 1
cell.EntireRow.Font.ColorIndex = 4
End Select
cell.EntireRow.Interior.ColorIndex = cell_colour
Next
End Sub
2- Macro to add column in Sheet1 with header Name Sheet 1
Private Sub CommandButton1_Click()
Dim rngUsernameHeader As Range
Dim rngHeaders As Range
Set rngHeaders = Range("1:1") 'Looks in entire first row.
Set rngUsernameHeader = rngHeaders.Find(what:="ID", After:=Cells(1, 1))
rngUsernameHeader.Offset(0, 1).EntireColumn.Insert
rngUsernameHeader.Offset(0, 1).Value = "Name"
End Sub
What iam looking for
Single Macro which can do
1 & 2 and also vlookup iD from sheet1 in data sheet(Id & name) and return name on newly added column(Name) in sheet1
=VLOOKUP(E2,Data!A:B,2,FALSE)
Can you pls help on this
Thanks HR
Case Else
in the middle of theSelect Case
code? – BruceWayne"add column with name and vlookup iD "
? Maybe if you included a screenshot with what you have, and what you want as output? – pgSystemTester