hsandeep
Well-known Member
- Joined
- Dec 6, 2008
- Messages
- 1,214
- Office Version
- 2010
- Platform
- Windows
- Mobile
I am using a code in a Worksheet.
The code:
The code line
Should check if the value in the 10th row and col column of the current worksheet (as defined by the With statement) is equal to 1.
If the condition is true, then the code inside the If block should get executed. If the condition is false, then the code inside the If block should be skipped.
But the code is not entering the code lines after the If statement & jumps to
PLEASE RECTIFY THE CODE. Also, please check whether the code line is correct or not for column FV:GZ
Thanks
The code:
Rich (BB code):
Private Sub FreezeValues()
Dim sheetName As String, targetRange As Range, targetCell As Range
sheetName = "l1" ' The name of your sheet
Application.ScreenUpdating = False
With ThisWorkbook.Sheets(sheetName)
Dim col As Integer
For col = 178 To 208 ' Column numbers for FV to GZ
If .Cells(10, col).Value = 1 Then
Set targetRange = .Range(.Cells(14, col).Address & ":" & .Cells(28, col).Address)
For Each targetCell In targetRange
If Not targetCell.HasFormula Then
Application.EnableEvents = False
targetCell.Value = targetCell.Value2
Application.EnableEvents = True
End If
Next targetCell
Set targetCell = .Cells(65, col)
If Not targetCell.HasFormula Then
Application.EnableEvents = False
targetCell.Value = targetCell.Value2
Application.EnableEvents = True
End If
End If
Next col
End With
Application.ScreenUpdating = True
End Sub
The code line
Rich (BB code):
If .Cells(10, col).Value = 1 Then
If the condition is true, then the code inside the If block should get executed. If the condition is false, then the code inside the If block should be skipped.
But the code is not entering the code lines after the If statement & jumps to
Rich (BB code):
End If
Next targetCell
Rich (BB code):
For col = 178 To 208 ' Column numbers for FV to GZ
Thanks