exceltadpole
Board Regular
- Joined
- Jan 14, 2004
- Messages
- 108
Consider this code snippet:
Dim selectedCell As Range
' ......
' several lines of code that handle the selectedCell variable go here
' ......
Sheets("items").Range("j34") = selectedCell.Offset(0, 5).Value
The above works correctly.
Here is a sample of values that may be found in selectedCell.Offset(0, 5)
AAA987
NMEK9745
PJ36ED9W
AAMPUERF9
DGK73
How can I include the following to the above code:
Before the assignment of "Sheets("items").Range("j34") = selectedCell.Offset(0, 5).Value" happens, the "selectedCell.Offset(0, 5).Value" must be checked.
If the first 2 characters contain "AA" then continue with the above assignment.
If the first 2 characters do not contain "AA" then just do a MsgBox "AA not found".
Given the above sample, only 2 values "AAA987" and "AAMPUERF9" would be assigned.
Not being a VBA expert, I am having difficulty with this conditional assignment.
Dim selectedCell As Range
' ......
' several lines of code that handle the selectedCell variable go here
' ......
Sheets("items").Range("j34") = selectedCell.Offset(0, 5).Value
The above works correctly.
Here is a sample of values that may be found in selectedCell.Offset(0, 5)
AAA987
NMEK9745
PJ36ED9W
AAMPUERF9
DGK73
How can I include the following to the above code:
Before the assignment of "Sheets("items").Range("j34") = selectedCell.Offset(0, 5).Value" happens, the "selectedCell.Offset(0, 5).Value" must be checked.
If the first 2 characters contain "AA" then continue with the above assignment.
If the first 2 characters do not contain "AA" then just do a MsgBox "AA not found".
Given the above sample, only 2 values "AAA987" and "AAMPUERF9" would be assigned.
Not being a VBA expert, I am having difficulty with this conditional assignment.