NLITech
asked on
Refer to the codename Sheet1 instead of the Tab name
I have recorded the following Macro:
Sub Mars()
Sheets.Add After:=Sheets(Sheets.Count )
Range("A2").Select
ActiveCell.FormulaR1C1 = _
"=IF(Sheet1!RC[7]="""",""" ",TEXT(She et1!RC[7], ""00000000 0000"")&TE XT(Sheet1! RC[8],""00 00000000"" ))"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A25 00"), Type:=xlFillDefault
End Sub
I would like to refer to the codename Sheet1 instead of the Tab name (in case the tab name changes), but I have been unable to figure this out. I have tried “Sheets1”, but when I run the Macro I am presented with windows Explorer.
Thank you for your help,
Lori
Sub Mars()
Sheets.Add After:=Sheets(Sheets.Count
Range("A2").Select
ActiveCell.FormulaR1C1 = _
"=IF(Sheet1!RC[7]="""","""
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A25
End Sub
I would like to refer to the codename Sheet1 instead of the Tab name (in case the tab name changes), but I have been unable to figure this out. I have tried “Sheets1”, but when I run the Macro I am presented with windows Explorer.
Thank you for your help,
Lori
Press F4 to view the sheet properties and change the name:
Substitute Sheet1.Range() for Sheet1!
E.g., Sheet1.Range(RC[7])
E.g., Sheet1.Range(RC[7])
ASKER
I am giving this Macro to other people. I want it to use the first tab regardless of what it is named.
ASKER
Mark,
Like this:
Sub Mars()
Sheets.Add After:=Sheets(Sheets.Count )
Range("A2").Select
ActiveCell.FormulaR1C1 = _
"=IF(Sheet1.Range(RC[7])=" ""","""",T EXT Worksheets(Sheet1.Range(RC [7]),""000 000000000" ")&TEXT Worksheets(Sheet1.range(RC [8]),""000 0000000"") )"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A25 00"), Type:=xlFillDefault
End Sub
?
Like this:
Sub Mars()
Sheets.Add After:=Sheets(Sheets.Count
Range("A2").Select
ActiveCell.FormulaR1C1 = _
"=IF(Sheet1.Range(RC[7])="
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A25
End Sub
?
Hi, NLITech.
Please see attached. I rename Sheet1 and also gave it a Codename of "Fred". The macro will continue to work even if the Sheet's Name (not Codename!) is changed.
The code is...
Brian.CodeName-Formula.xlsm
Please see attached. I rename Sheet1 and also gave it a Codename of "Fred". The macro will continue to work even if the Sheet's Name (not Codename!) is changed.
The code is...
Option Explicit
Sub Mars()
Sheets.Add After:=Sheets(Sheets.Count)
Range("A2").Select
ActiveCell.FormulaR1C1 = _
"=IF('" & Fred.Name & "'!RC[7]="""","""",TEXT('" & Fred.Name & "'!RC[7],""000000000000"")&TEXT('" & Fred.Name & "'!RC[8],""0000000000""))"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A2500"), Type:=xlFillDefault
End Sub
Regards,Brian.CodeName-Formula.xlsm
Correct, NLITech. That should do what you need, I think.
sheet1.select will select the index of the sheet
sheets(1).select will select the one to the far left.
sheets(1).select will select the one to the far left.
ASKER
Mark,
That gives me #Name? as the result.
Brian,
I am still trying to comprehend, waiting for workbook to open.
tdlewis,
Not what I am looking for.
Thanks
That gives me #Name? as the result.
Brian,
I am still trying to comprehend, waiting for workbook to open.
tdlewis,
Not what I am looking for.
Thanks
NLITech,
"waiting for workbook to open."
I downloaded the file and it's still working fine for me. Please restart Excel and try the file again.
Thanks,
Brian.
"waiting for workbook to open."
I downloaded the file and it's still working fine for me. Please restart Excel and try the file again.
Thanks,
Brian.
ASKER
albelo,
I get a Application-defined or object-refined error with:
ActiveCell.FormulaR1C1 = _
"=IF(Sheets(1).select(RC[7 ])="""","" "",TEXT Worksheets(Sheets(1).selec t(RC[7])," "000000000 000"")&TEX T Worksheets(Sheets(1).selec t(RC[8])," "000000000 0""))"
I get a Application-defined or object-refined error with:
ActiveCell.FormulaR1C1 = _
"=IF(Sheets(1).select(RC[7
ASKER
Brian,
I do not wish to rename the code name, so I am not sure how to use this.
Lori
I do not wish to rename the code name, so I am not sure how to use this.
Lori
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brian,
Thank you for dumb it down for me, I needed that. Worked perfectly!
Lori
Thank you for dumb it down for me, I needed that. Worked perfectly!
Lori
Thanks, Lori. Glad to help.