makeitwork09
Technical User
I am using Excel 2007 and I have the following macro which, from a range with a formula in the cells, finds the cell with the result (value) of 1.
I used that to the determine the row. The row number is then used to make a range selection starting at the row where the 1 value was found, but in a different column.
Using that selection, I use the sheet name to create a worksheet level named range.
I need to enhance this code in the following way:
(1) I have several sheets where I need to repeat the above, therefore I need to loop through the sheets. I only need this for the sheets that have a name that is a number.
(2) The column with the formula where the value is 1 is column A. With the current code, if, when the macro is executed, the selected cell is not already in column A, the search for the value of 1 is done on the column that is selected at exectution, instead. I need to change that. I tried range(a1).select, but for some reason the rest of the code didn't work.
(3) If the value of 1 is not found I want to continue the next sheet
(4) Below I only show one column that I am naming, but there is a second column where I need to do the same steps.
If someone could assist with this that would be apprecitated.
I used that to the determine the row. The row number is then used to make a range selection starting at the row where the 1 value was found, but in a different column.
Using that selection, I use the sheet name to create a worksheet level named range.
I need to enhance this code in the following way:
(1) I have several sheets where I need to repeat the above, therefore I need to loop through the sheets. I only need this for the sheets that have a name that is a number.
(2) The column with the formula where the value is 1 is column A. With the current code, if, when the macro is executed, the selected cell is not already in column A, the search for the value of 1 is done on the column that is selected at exectution, instead. I need to change that. I tried range(a1).select, but for some reason the rest of the code didn't work.
(3) If the value of 1 is not found I want to continue the next sheet
(4) Below I only show one column that I am naming, but there is a second column where I need to do the same steps.
If someone could assist with this that would be apprecitated.
Code:
Sub FindPeriod1()
'
' FindPeriod1 Macro
'
' Keyboard Shortcut: Ctrl+p
'
Dim SheetName As String, NameAddress As String
SheetName = "=" & Sheet4.Name & "!"
Range(Selection, Selection.End(xlDown)).Select
Selection.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
Range("d" & ActiveCell.Row).Select
NameAddress = Range(Selection, Selection.End(xlDown)).Select
'Add the name MyRange
ActiveSheet.Names.Add Name:="payment", RefersTo:=Selection
'ActiveWorkbook.Names.Add(Name:="payment", RefersTo:=SheetName & NameAddress)
End Sub