CADim_JParker
New Member
- Joined
- Feb 27, 2024
- Messages
- 4
- Office Version
- 365
- 2021
- 2019
- 2016
- Platform
- Windows
All,
I decided to make my first post a fun one.
I am working on some code to essentially find any cell in a given range that has text and append .01 to the end of it, but need to skip any cell that is blank or null.
Currently this is working ok, except when it skips a blank cell lets say row 9 and goes to the Next SelRange, it skips to row 11.
Code:
Sub RevPropUpdate()
Dim SelRange As Range
Dim ColNum As Integer
Dim CWS As Worksheet, TmpWS As Worksheet
'Find the column number where the column header is
Set CWS = ActiveSheet
ColNum = Application.WorksheetFunction.Match("Revision", CWS.Rows(1), 0)
'Set the column range to work with
Set SelRange = CWS.Columns(ColNum)
'Add a worksheet to put '1' onto the clipboard, ensures no issues on activesheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set TmpWS = ThisWorkbook.Worksheets.Add
With TmpWS
.Cells(1, 1) = 1
.Cells(1, 1).Copy
End With
'Select none blank cells using special cells...much faster than looping through all cells
Set SelRange = SelRange.SpecialCells(xlCellTypeConstants, 23)
SelRange.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
TmpWS.Delete
CWS.Select
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'Adjust range to remove header row
Set SelRange = SelRange.Offset(1, 0)
SelRange.Select
'Modify each cell within the selected range
For Each SelRange In Selection
If IsEmpty(SelRange) Then
GoTo NextCell
ElseIf Not IsNull(SelRange.Value) Then
SelRange.Value = SelRange.Value & ".01"
End If
NextCell:
Next SelRange
End Sub
I decided to make my first post a fun one.
I am working on some code to essentially find any cell in a given range that has text and append .01 to the end of it, but need to skip any cell that is blank or null.
Currently this is working ok, except when it skips a blank cell lets say row 9 and goes to the Next SelRange, it skips to row 11.
Code:
Sub RevPropUpdate()
Dim SelRange As Range
Dim ColNum As Integer
Dim CWS As Worksheet, TmpWS As Worksheet
'Find the column number where the column header is
Set CWS = ActiveSheet
ColNum = Application.WorksheetFunction.Match("Revision", CWS.Rows(1), 0)
'Set the column range to work with
Set SelRange = CWS.Columns(ColNum)
'Add a worksheet to put '1' onto the clipboard, ensures no issues on activesheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set TmpWS = ThisWorkbook.Worksheets.Add
With TmpWS
.Cells(1, 1) = 1
.Cells(1, 1).Copy
End With
'Select none blank cells using special cells...much faster than looping through all cells
Set SelRange = SelRange.SpecialCells(xlCellTypeConstants, 23)
SelRange.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
TmpWS.Delete
CWS.Select
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'Adjust range to remove header row
Set SelRange = SelRange.Offset(1, 0)
SelRange.Select
'Modify each cell within the selected range
For Each SelRange In Selection
If IsEmpty(SelRange) Then
GoTo NextCell
ElseIf Not IsNull(SelRange.Value) Then
SelRange.Value = SelRange.Value & ".01"
End If
NextCell:
Next SelRange
End Sub