Edgarvelez
Board Regular
- Joined
- Jun 6, 2019
- Messages
- 197
- Office Version
- 2016
- Platform
- Windows
Hi,
Very new to VBA and I have a code that works great.
All it really does is selects the value of a cell in sheet one goes to another sheet finds it and copies the cell to the right of it and then goes on and paste the the vale to another sheet.
If it does not find this specific value then I get "Run-time error "91": Object variable or With block variable not set" which is ok because it could not find what it was looking for.
I would like to add a message box so it can display "Description Code Not Found Add to Database"
and I would like to reset the macro back to the beginning.
sh1.Range("D21").Select
rngY = ActiveCell.Value
Sheets(Range("D7").Value).Select
Columns("A:A").Select
Selection.Find(What:=rngY, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Activate
ActiveCell.Copy
sh2.Cells(Rows.Count, 12).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
sh2.Cells(Rows.Count, 26).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
sh2.Cells(Rows.Count, 18).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
sh2.Cells(Rows.Count, 25).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Very new to VBA and I have a code that works great.
All it really does is selects the value of a cell in sheet one goes to another sheet finds it and copies the cell to the right of it and then goes on and paste the the vale to another sheet.
If it does not find this specific value then I get "Run-time error "91": Object variable or With block variable not set" which is ok because it could not find what it was looking for.
I would like to add a message box so it can display "Description Code Not Found Add to Database"
and I would like to reset the macro back to the beginning.
sh1.Range("D21").Select
rngY = ActiveCell.Value
Sheets(Range("D7").Value).Select
Columns("A:A").Select
Selection.Find(What:=rngY, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Activate
ActiveCell.Copy
sh2.Cells(Rows.Count, 12).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
sh2.Cells(Rows.Count, 26).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
sh2.Cells(Rows.Count, 18).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
sh2.Cells(Rows.Count, 25).End(xlUp)(2).Resize(sh1.Range("D28").Value).PasteSpecial xlPasteValues
Application.CutCopyMode = False