matrix26
Board Regular
- Joined
- Dec 16, 2020
- Messages
- 57
- Office Version
- 365
- Platform
- Windows
Hi,
I have a workbook that has 3 worksheets. DEVICE INFO, CCT INFO, SIA.
I'm trying to create a VBA macro that will ask the user to select a range from column A on worksheet DEVICE INFO
then I want the script to use that selected range to look up column A on worksheet CCT INFO in order to find the corresponding data for that device in column B of worksheet CCT INFO.
then I need the script to copy everything to worksheet SIA in the following format
Service Affected and Tail Circuit data comes from the CCT INFO worksheet, whereas Node comes from the copied range on worksheet DEVICE INFO
I can get the script to do everything I need EXCEPT sometimes in the worksheet CCT INFO contains multiple entries for the NODE with different details in worksheet CCT INFO column B.
i.e CCT INFO might have the following data
test device name 1 TEST DATA 2
test device name 1 TEST DATA 4
test device name 1 TEST DATA
I can't get my script to find those extra entries, it always stops looking once it's found the 1st entry.
Can anyone help me amend my code so it works?
Here is the lookup part of my code
' Copy data from Column J of DEVICE INFO to Column B of SIA
lastRow = sia.Cells(sia.Rows.count, "B").End(xlUp).Row + 1
deviceRange.Offset(0, 9).Copy sia.Cells(lastRow, "B")
' Copy data from Column L of DEVICE INFO to Column E of SIA
deviceRange.Offset(0, 11).Copy sia.Cells(lastRow, "E")
' Perform lookup on CCT INFO and fill the corresponding data in SIA
lastRow = sia.Cells(sia.Rows.count, "I").End(xlUp).Row
Set lookupRange = cctInfo.Range("A:B")
For Each cell In sia.Range("I2:I" & lastRow)
Set lookupResult = lookupRange.Columns(1).Find(What:=cell.value, LookAt:=xlWhole)
If Not lookupResult Is Nothing Then
sia.Cells(cell.Row, "A").value = lookupResult.Offset(0, 1).value ' Populate column A with corresponding value from CCT INFO
sia.Cells(cell.Row, "C").value = "C&WW"
sia.Cells(cell.Row, "D").value = "Loss of Service"
sia.Cells(cell.Row, "F").value = "IPVPN Access"
sia.Cells(cell.Row, "G").value = "N/A"
sia.Cells(cell.Row, "H").value = "N/A"
sia.Cells(cell.Row, "J").value = "Yes"
sia.Cells(cell.Row, "K").value = "Live"
sia.Cells(cell.Row, "L").value = lookupResult.Offset(0, 1).value ' Populate column A with corresponding value from CCT INFO
sia.Cells(cell.Row, "M").value = "N/A"
sia.Cells(cell.Row, "N").value = "N/A"
Else
MsgBox "Entry not found for device: " & cell.value
End If
Next cell
MsgBox "Data copied to SIA successfully!"
I have a workbook that has 3 worksheets. DEVICE INFO, CCT INFO, SIA.
I'm trying to create a VBA macro that will ask the user to select a range from column A on worksheet DEVICE INFO
then I want the script to use that selected range to look up column A on worksheet CCT INFO in order to find the corresponding data for that device in column B of worksheet CCT INFO.
then I need the script to copy everything to worksheet SIA in the following format
Service Affected | Customer | Sub-Group | Service Impact | Address | Service Type | Service Model | Customer Reference | Node | Notify | Circuit Status | Tail Circuit | Customer PID | Key Owner |
TEST DATA 2 | customer name | test data | Loss of Service | business address | IPVPN Access | N/A | N/A | test device name 1 | Yes | Live | TEST DATA 2 | N/A | N/A |
TEST DATA 3 | customer name | test data | Loss of Service | business address | IPVPN Access | N/A | N/A | test device name 2 | Yes | Live | TEST DATA 3 | N/A | N/A |
Service Affected and Tail Circuit data comes from the CCT INFO worksheet, whereas Node comes from the copied range on worksheet DEVICE INFO
I can get the script to do everything I need EXCEPT sometimes in the worksheet CCT INFO contains multiple entries for the NODE with different details in worksheet CCT INFO column B.
i.e CCT INFO might have the following data
test device name 1 TEST DATA 2
test device name 1 TEST DATA 4
test device name 1 TEST DATA
I can't get my script to find those extra entries, it always stops looking once it's found the 1st entry.
Can anyone help me amend my code so it works?
Here is the lookup part of my code
' Copy data from Column J of DEVICE INFO to Column B of SIA
lastRow = sia.Cells(sia.Rows.count, "B").End(xlUp).Row + 1
deviceRange.Offset(0, 9).Copy sia.Cells(lastRow, "B")
' Copy data from Column L of DEVICE INFO to Column E of SIA
deviceRange.Offset(0, 11).Copy sia.Cells(lastRow, "E")
' Perform lookup on CCT INFO and fill the corresponding data in SIA
lastRow = sia.Cells(sia.Rows.count, "I").End(xlUp).Row
Set lookupRange = cctInfo.Range("A:B")
For Each cell In sia.Range("I2:I" & lastRow)
Set lookupResult = lookupRange.Columns(1).Find(What:=cell.value, LookAt:=xlWhole)
If Not lookupResult Is Nothing Then
sia.Cells(cell.Row, "A").value = lookupResult.Offset(0, 1).value ' Populate column A with corresponding value from CCT INFO
sia.Cells(cell.Row, "C").value = "C&WW"
sia.Cells(cell.Row, "D").value = "Loss of Service"
sia.Cells(cell.Row, "F").value = "IPVPN Access"
sia.Cells(cell.Row, "G").value = "N/A"
sia.Cells(cell.Row, "H").value = "N/A"
sia.Cells(cell.Row, "J").value = "Yes"
sia.Cells(cell.Row, "K").value = "Live"
sia.Cells(cell.Row, "L").value = lookupResult.Offset(0, 1).value ' Populate column A with corresponding value from CCT INFO
sia.Cells(cell.Row, "M").value = "N/A"
sia.Cells(cell.Row, "N").value = "N/A"
Else
MsgBox "Entry not found for device: " & cell.value
End If
Next cell
MsgBox "Data copied to SIA successfully!"