Count rows, split in half, assign value to cell

cgmojoco

Well-known Member
Joined
Jan 15, 2005
Messages
699
Hi there-

Would like a macro that would do the following process to each sheet in the workbook.

Count the number of rows that have data in them (excluding row one), then divide the rows by 2 (not necessarily always an even number of rows-Round up?):

1st half would have value, user 1 added to cells in column H for each row
2nd hafl would have value, user 2 added to cells in column H for each row

Next sheet would be selected and same operation would run.

This code would allow me to skip specific sheets. I would like to skip sheets labeled MITCHELLMOD and MITCHELLRX

Then I would like to freeze panes on each sheet with A2 as the active sheet when freezing. (not skipping sheets)

Thanks in advance.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi

How about
Code:
Sub aaa()
 For Each sh In ActiveWorkbook.Sheets
  If sh.Name <> "MITCHELLMOD" And sh.Name <> "MITCHELLRX" Then
   lastcell = sh.Cells.SpecialCells(xlCellTypeLastCell).Row
   sh.Range("H2:H" & Int(lastcell / 2)).Value = "user 1"
   sh.Range("h" & Int(lastcell / 2) + 1 & ":h" & lastcell).Value = "user 2"
  End If
 sh.Select
 Range("a2").Select
 ActiveWindow.FreezePanes = True
Next sh

End Sub


Tony
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

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