Hi All,
I'm hoping someone can point me in the right direction, I have the below code that looks for a number in column A if it finds it then the adjacent cells CentreAcrossSelection. I've found this is much easier than merging the cells.
But I'm getting a run time '91' error message when running?
Public Sub CenterValues()
Dim rng As Range, _
rng1 As Range, _
LR As Long
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1:A" & LR)
Set rng = .Find("1", LookIn:=xlValues, lookAt:=xlPart)
If Not rng Is Nothing Then
rng1 = rng.Address
Do
rng.Resize(1, 7).HorizontalAlignment = xlCenterAcrossSelection
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And rng.Address <> rng1
End If
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Any ideas why this is happening? and any tips on how to correct?
Thanks in advance for looking
Rob
I'm hoping someone can point me in the right direction, I have the below code that looks for a number in column A if it finds it then the adjacent cells CentreAcrossSelection. I've found this is much easier than merging the cells.
But I'm getting a run time '91' error message when running?
Public Sub CenterValues()
Dim rng As Range, _
rng1 As Range, _
LR As Long
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1:A" & LR)
Set rng = .Find("1", LookIn:=xlValues, lookAt:=xlPart)
If Not rng Is Nothing Then
rng1 = rng.Address
Do
rng.Resize(1, 7).HorizontalAlignment = xlCenterAcrossSelection
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And rng.Address <> rng1
End If
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Any ideas why this is happening? and any tips on how to correct?
Thanks in advance for looking
Rob