VBA to Replace all with hidden rows & columns

CDThe1

New Member
Joined
Mar 27, 2016
Messages
18
Hello all,

I have a macro that will replace all within a workbook, but it won't replace if rows/columns are hidden. How can I make it so it will replace in hidden rows and columns? Thank you in advance

Sub FindReplaceAll()
'PURPOSE: Find & Replace text/values throughout entire workbook
sht As WorksheetDim
fnd As VariantDim
rplc As

Variantfnd = "April"
rplc = "May"
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace what:=fnd,
Replacement:=rplc, _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _ SearchFormat:=False, ReplaceFormat:=False
Next sht
End Sub
 
I'm trying with 4 sheets and it doesn't stop on the second one.
In all 4 sheets I have hidden rows and hidden columns and the replacement does it in all of them.

Do you have any other macros in the book?
Do you have macros in the events of any sheet?
 
Upvote 0
I'm trying with 4 sheets and it doesn't stop on the second one.
In all 4 sheets I have hidden rows and hidden columns and the replacement does it in all of them.

Do you have any other macros in the book?
Do you have macros in the events of any sheet?
So, I started from scratch with a fresh workbook as an example, and the macro works perfectly. Then I looked at my original file and see that some rows are hidden while others are grouped. That appears to be the issue. Is there an addition I can make so it will replace in grouped rows as well? Thanks for all your help, by the way.
 
Upvote 0
others are grouped

Check the following, including checking rows hidden by autofilter.

VBA Code:
Sub FindReplaceAll()
  'PURPOSE: Find & Replace text/values throughout entire workbook
  Dim sht As Worksheet
  Dim fnd As String
  Dim rplc As String
  Dim c As Range
  Dim lr As Long, lc As Long
  
  fnd = "April"
  rplc = "May"
  For Each sht In ThisWorkbook.Worksheets
    lr = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
    lc = sht.UsedRange.Columns(sht.UsedRange.Columns.Count).Column
    For Each c In sht.Range("A1", sht.Cells(lr, lc)).Cells
      If c.Value = fnd Then
        lr = lr
      End If
      c.Value = Replace(c.Value, fnd, rplc, , , vbTextCompare)
    Next
  Next sht
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,795
Messages
6,193,045
Members
453,772
Latest member
aastupin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top