error in While loop

adr12345

Board Regular
Joined
Jan 19, 2015
Messages
67
I have this code, to replace specific text in all sheets in same column.
It should automatically count cells in first column and accordingly run While loop.
But code is not able to count number of cells everytime. in Other words variable count value is not changing

Dim count As Integer
For Each ws In Worksheets
count = ActiveSheet.range("A:A").Cells.SpecialCells(xlCellTypeConstants).count
i = 2
While i < count
Cells(i, Cells(Application.WorksheetFunction.Match("Tech", Rows(1), 0)).COlumn).Value = Replace(Cells(i, Cells(Application.WorksheetFunction.Match("Tech", Rows(1), 0)).COlumn).Value, "NNNN", "PP")
i = i + 1
Wend
Next ws
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You probably need to put ws. in front of everywhere it says Cells (except the one in my p.s. statement below) and depending on what you are trying to do exactly also replace ActiveSheet with ws

p.s. you also don't need the cells in

Code:
ActiveSheet.range("A:A").Cells.SpecialCells(xlCellTypeConstants).count

i.e.

Code:
ActiveSheet.Range("A:A").SpecialCells(xlCellTypeConstants).count
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,840
Members
449,411
Latest member
adunn_23

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