VBA Beginner 2024
New Member
- Joined
- Jan 30, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
I am trying to use VBA to clear contents of a group of cells in a row based on data in various columns:
Example:
IF Column A or G is Y i want to clear contents of B to F or H to L respectively.
I have the following using different columns but for example in row 3, it would delete data in B to F instead of H to L.
Dim lr As Long, i As Long
lr = Cells(Rows.Count, "X").End(xlUp).Row
For i = 2 To lr
If UCase(Cells(i, "X")) = "Y" Then Cells(i, "Y").Resize(1, 5).ClearContents
Next i
lr = Cells(Rows.Count, "AC").End(xlUp).Row
For i = 2 To ls
If UCase(Cells(i, "AC")) = "Y" Then Cells(i, "Y").Resize(1, 5).ClearContents
Next i
How would i write the second part to focus on 2nd set of columns vs the first?
Example:
IF Column A or G is Y i want to clear contents of B to F or H to L respectively.
I have the following using different columns but for example in row 3, it would delete data in B to F instead of H to L.
Dim lr As Long, i As Long
lr = Cells(Rows.Count, "X").End(xlUp).Row
For i = 2 To lr
If UCase(Cells(i, "X")) = "Y" Then Cells(i, "Y").Resize(1, 5).ClearContents
Next i
lr = Cells(Rows.Count, "AC").End(xlUp).Row
For i = 2 To ls
If UCase(Cells(i, "AC")) = "Y" Then Cells(i, "Y").Resize(1, 5).ClearContents
Next i
How would i write the second part to focus on 2nd set of columns vs the first?