Move to the next cell
Solved
Olive
-
Olive -
Olive -
Hello,
I'm sorry to ask you such a simple thing, but I've just started with VBA.
Problem No. 1:
Let me explain, I have a list of names like below and I would like to use a macro that allows me to bold the last name of each person.
Name1
Name1
Name1 => name in bold
Name2
Name2
Name2
Name2 => name in bold
Name3
Name3
Name3
Name3 => name in bold
Name4
Name4 => name in bold
Actually, I have a second problem here:
Problem No. 2:
The number of lines in my list is random every week, so some weeks I might have 4 different names in my list or other weeks I might have a dozen different names. My problem here is that I can't set a random limit for my macro.
Here is my attempt at a macro:
Sub FR_NoircirVendeurs()
Dim Range As Range
Dim Cell As Range
Set Range = Range("B2:...") => my Problem No. 2
For Each Cell In Range
If Cell.Value = Cell.Offset(1, 0).Value Then
Step 1 => my problem No. 1 is located here (I think)
End If
Next Cell
If Cell.Value <> Cell.Offset(1, 0).Value Then
Cell.Font.Bold = True
End If
Next Cell
End Sub
I hope I was clear enough in my explanations.
Thank you in advance for any help you can provide.
P.S.: Thanks to commentcamarche.net which helps me in my VBA learning.
I'm sorry to ask you such a simple thing, but I've just started with VBA.
Problem No. 1:
Let me explain, I have a list of names like below and I would like to use a macro that allows me to bold the last name of each person.
Name1
Name1
Name1 => name in bold
Name2
Name2
Name2
Name2 => name in bold
Name3
Name3
Name3
Name3 => name in bold
Name4
Name4 => name in bold
Actually, I have a second problem here:
Problem No. 2:
The number of lines in my list is random every week, so some weeks I might have 4 different names in my list or other weeks I might have a dozen different names. My problem here is that I can't set a random limit for my macro.
Here is my attempt at a macro:
Sub FR_NoircirVendeurs()
Dim Range As Range
Dim Cell As Range
Set Range = Range("B2:...") => my Problem No. 2
For Each Cell In Range
If Cell.Value = Cell.Offset(1, 0).Value Then
Step 1 => my problem No. 1 is located here (I think)
End If
Next Cell
If Cell.Value <> Cell.Offset(1, 0).Value Then
Cell.Font.Bold = True
End If
Next Cell
End Sub
I hope I was clear enough in my explanations.
Thank you in advance for any help you can provide.
P.S.: Thanks to commentcamarche.net which helps me in my VBA learning.
Configuration: Windows XP Internet Explorer 6.0
1 answer
-
Hello Olive,
without using VBA, you can bold the last name using conditional formatting (make the cell bold if its content is different from the content of the next cell)
if you absolutely want to use your macro:
1°) completely remove this part, which is incorrect and serves no purpose. The For Each ... Next loop already moves from one cell to the next, no need to add anything.
If Cellule.Value = Cellule.Offset(1, 0).Value Then
Step 1 => my Problem No. is found here (I think)
End If
Next Cellule
2°) Since the cells you are processing are consecutive, use the .End(xlDown) function to find the end of your range. It's equivalent to pressing Shift+Ctrl+down arrow from B2.
Set Plage = Range(Range("B2"), Range("B2").End(xlDown))
I.