VBAProIWish
Well-known Member
- Joined
- Jul 6, 2009
- Messages
- 1,027
- Office Version
- 365
- Platform
- Windows
Hello All,
I am looking for code to do the following...
1. Find the column (in row 1) named "Customer Number"
2. Find the column (in row 1) named "Model Number"
3. Find the column (in row 1) named "Model Color"
4. For every cell in the "Model Number" column named "Sky", populate the cell in the "Model Color" column (same row), "Blue".
5. For every cell in the "Model Number" column that is blank, populate the cell in the "Model Color" column (same row), "No Color".
6. For every cell in the "Model Number" column with any combination of ONLY numbers (whole numbers, integers), populate the cell in the "Model Color" column (same row), "Yellow".
7. There will be blanks in the "Model Number" column, but the search needs to stop at the last populated cell in the "Customer Number" column, where there are no blanks.
Putting it more simply...
If the cell in the "Model Number" column says "Sky", make the cell in the "Model Color" column, "Blue", etc...
Please note the following...
1. Everything is based on row 2, downward. (Row 1 is for Column Headers).
2. Due to my columns never being in the same place, I would like this to find columns by name and not by column position.
3. This needs to work on whatever number format the "Model Number" column is currently in. Text, numbers, accounting, etc.
My code below works fine with text, but not on long numbers like this C480000B9147-0009-08.
It also isn't programmed by column header name.
4. The code needs to be cAsE INsENTivE. Sometimes in my lines of code, "Sky" for example, works, but "SKY" or "sky" doesn't work.
This code only works by column position and doesn't work if there are long numbers in column D
Thanks much to anyone that can help me with this
I am looking for code to do the following...
1. Find the column (in row 1) named "Customer Number"
2. Find the column (in row 1) named "Model Number"
3. Find the column (in row 1) named "Model Color"
4. For every cell in the "Model Number" column named "Sky", populate the cell in the "Model Color" column (same row), "Blue".
5. For every cell in the "Model Number" column that is blank, populate the cell in the "Model Color" column (same row), "No Color".
6. For every cell in the "Model Number" column with any combination of ONLY numbers (whole numbers, integers), populate the cell in the "Model Color" column (same row), "Yellow".
7. There will be blanks in the "Model Number" column, but the search needs to stop at the last populated cell in the "Customer Number" column, where there are no blanks.
Putting it more simply...
If the cell in the "Model Number" column says "Sky", make the cell in the "Model Color" column, "Blue", etc...
Please note the following...
1. Everything is based on row 2, downward. (Row 1 is for Column Headers).
2. Due to my columns never being in the same place, I would like this to find columns by name and not by column position.
3. This needs to work on whatever number format the "Model Number" column is currently in. Text, numbers, accounting, etc.
My code below works fine with text, but not on long numbers like this C480000B9147-0009-08.
It also isn't programmed by column header name.
4. The code needs to be cAsE INsENTivE. Sometimes in my lines of code, "Sky" for example, works, but "SKY" or "sky" doesn't work.
This code only works by column position and doesn't work if there are long numbers in column D
VBA Code:
Sub Populate_Dynamically
Dim lastRow As Long, icell As Long
lastRow = Range("C" & Rows.Count).End(xlUp).Row
For icell = 1 To lastRow
If Range("D" & icell).Value = "Sky" Then
Range("E" & icell).Value = "Blue"
End If
Next icell
End Sub
Thanks much to anyone that can help me with this