I have this VBA code that changes values in a range if the day is before today. The code…
Jump to turn (8)
- 1I have this VBA code that changes values in a range if the day is before today.
- 2your code is still looking for the value 'a'
- 3Code does not take into account that it should only change the values of cells b
- 4As I previously mentioned the previous VBA code worked well. If you compare your
- 5The VBA code you provided works perfectly, Can you please write a similar one th
- 6No errors in the code but it does not change values found in the next month to '
- 7It worked perfectly. Can you please write me a final code that will change all n
- 8In cell BP2, I have the following formula '=TEXT(BN2,"dd/mm") & " to " & TEXT(BO
- User
I have this VBA code that changes values in a range if the day is before today. The code works very well. Can the code be amended so that instead of looking for the value 'a' it looks for cells that are not empty and restrict the range to B2:BK7
Sub ChangeAtoE_CurrentMonth()
Dim ws As Worksheet Dim LastCol As Long, CurrentCol As Long Dim FoundA As Boolean Dim Row As Long Dim col As Long
Set ws = ThisWorkbook.Worksheets("Leave")
' Find the last column with data LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
' Get the current date's day CurrentCol = Day(Date)
' Loop through rows from 2 onwards (skip headers) For Row = 2 To ws.UsedRange.Rows.Count
codeFoundA = False ' Flag to track if 'a' is found ' Loop from first column to column before current day 'For col = 1 To CurrentCol - 1 For col = 1 To CurrentCol If Not IsEmpty(ws.Cells(Row, col).Value) And VarType(ws.Cells(Row, col).Value) = vbString Then ' Check if cell contains 'a' and update to 'e' If ws.Cells(Row, col).Value = "a" Then ws.Cells(Row, col).Value = "e" FoundA = True ' Set flag if 'a' is found End If End If Next col