Hi all,
I have a worksheet containing data where row 1 is the column headings, and subsequent rows contain data about individuals with one row per person.
One of the columns contains the title "age", and I need to pick up this column and insert two columns after it, titled "age_low" and "age_high" which will simply contain a Y or N in each, depending on whether the person's age falls into the low bracket or the high bracket.
The code below is what I've got so far. I can find the "age" cell no problem and insert columns, but I'm a bit stuck at the tricker bit of saying "if value in the cell in the column titled "age" is between x and y, then the value of this cell is 'Y', else the value of this cell is 'N'".
Sub age_inserts()
Dim LastRow As Long
Dim FoundCell As Range
Dim FoundAge As String
LastRow = ActiveSheet.Cells(65536, 1).End(xlUp).Row
Rows("1:1").Select
Set FoundCell = Selection.Find(What:="age", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
FoundAge = FoundCell.Address
Range(FoundAge).Offset(0, 1).Select
ActiveCell.EntireColumn.Insert
ActiveCell.Value = "Age_high"
' do some calculations here to insert Y/N in column age_high
Range(FoundAge).Offset(0, 1).Select
ActiveCell.EntireColumn.Insert
ActiveCell.Value = "Age_low"
' do some calculations here to insert Y/N in column age_low
End Sub
Any pointers on where to go from here would be much appreciated!
Bookmarks