Seandobson2402
New Member
- Joined
- Feb 9, 2018
- Messages
- 23
Hi All,
I'm new to the VBA world and tryng to learn as much as possible. I have been studying for a few weeks now and I have managed to get an ok understanding. However, I seem to be stuck on the following code: -
Sub PREMISE_ID_1()
Dim Index As Long
Index = 8
Do While Index < 99000
If Sheet2.Cells(24, 10) = "" Then
MsgBox "Please enter Premise ID"
Exit Sub
End If
If Sheet2.Cells(24, 10) = Sheet1.Cells(Index, 9).Value Then
'Premise Id
Sheet2.Cells(30, 6).Value = Sheet1.Cells(Index, 9).Value
'Postcode
Sheet2.Cells(32, 6).Value = Sheet1.Cells(Index, 18).Value
'Add1
Sheet2.Cells(34, 6).Value = Sheet1.Cells(Index, 14).Value
'Add2
Sheet2.Cells(36, 6).Value = Sheet1.Cells(Index, 15).Value
'Add3
Sheet2.Cells(38, 6).Value = Sheet1.Cells(Index, 16).Value
'Account Status
Sheet2.Cells(40, 6).Value = Sheet1.Cells(Index, 25).Value
End If
Index = Index + 1
Loop
End Sub
The sub routine takes the value entered on Sheet2 "J24" and does an index lookup on Sheet1 to populate information into Sheet2 "F" rows 30, 32, 34, 36, 38 & 40. If J24 is blank, I get a MsgBox saying "Please enter Premise ID".
I would like to add in another MsgBox. Where, if the information in Sheet2 "J24" doesnt match any data on Sheet1, a box will pop up saying "ID number not found". Is this possible?
Kind regards
Sean
I'm new to the VBA world and tryng to learn as much as possible. I have been studying for a few weeks now and I have managed to get an ok understanding. However, I seem to be stuck on the following code: -
Sub PREMISE_ID_1()
Dim Index As Long
Index = 8
Do While Index < 99000
If Sheet2.Cells(24, 10) = "" Then
MsgBox "Please enter Premise ID"
Exit Sub
End If
If Sheet2.Cells(24, 10) = Sheet1.Cells(Index, 9).Value Then
'Premise Id
Sheet2.Cells(30, 6).Value = Sheet1.Cells(Index, 9).Value
'Postcode
Sheet2.Cells(32, 6).Value = Sheet1.Cells(Index, 18).Value
'Add1
Sheet2.Cells(34, 6).Value = Sheet1.Cells(Index, 14).Value
'Add2
Sheet2.Cells(36, 6).Value = Sheet1.Cells(Index, 15).Value
'Add3
Sheet2.Cells(38, 6).Value = Sheet1.Cells(Index, 16).Value
'Account Status
Sheet2.Cells(40, 6).Value = Sheet1.Cells(Index, 25).Value
End If
Index = Index + 1
Loop
End Sub
The sub routine takes the value entered on Sheet2 "J24" and does an index lookup on Sheet1 to populate information into Sheet2 "F" rows 30, 32, 34, 36, 38 & 40. If J24 is blank, I get a MsgBox saying "Please enter Premise ID".
I would like to add in another MsgBox. Where, if the information in Sheet2 "J24" doesnt match any data on Sheet1, a box will pop up saying "ID number not found". Is this possible?
Kind regards
Sean