1

I'm trying to automate the following process using a Excel but I'm experiencing some difficulties as obviously I need to set up a variable within the OFFSET function:

Sheets("XXX").Visible = True
Sheets("XXX").Select
ActiveWorkbook.Names.Add Name:="XXX_aaa", RefersToR1C1:= _
    "=OFFSET('XXX'!R2C1,0,1,COUNTA('XXX'!C1),21)"
Sheets("XXX").Visible = False

Sheets("YYY").Visible = True
Sheets("YYY").Select
ActiveWorkbook.Names.Add Name:="YYY_bbb", RefersToR1C1:= _
    "=OFFSET('YYY'!R2C1,0,1,COUNTA('YYY'!C1),21)"
Sheets("YYY").Visible = False

Sheets("ZZZ").Visible = True
Sheets("ZZZ").Select
ActiveWorkbook.Names.Add Name:="ZZZ_ccc", RefersToR1C1:= _
    "=OFFSET('ZZZ'!R2C1,0,1,COUNTA('ZZZ'!C1),21)"
Sheets("ZZZ").Visible = False`

Is there an easy macro function I can use to automate this task (it has to be repeated 30 times !)

Thanks !

2
  • Repeat 30 times is that how many sheets you have? Can you give us the Sheet Index you want to repeat it for? Sheets 1:30? or 2:31 for example? You have to at least have 1 sheet always visible also Commented Jun 11, 2013 at 16:02
  • Hi Yes I have a Control Sheet. It has to be repeated for Sheets 2 to 31. Commented Jun 11, 2013 at 16:10

1 Answer 1

1

Try this on a COPY of the workbook you are working with:

Sub Sample()
Dim intCurrentSheet As Integer
Dim lngLastRow As Long

For intCurrentSheet = 2 To 31

    lngLastRow = Sheets(intCurrentSheet).Range("U1048576").End(xlUp).Row

    Sheets(intCurrentSheet).Range("A2:U" & lngLastRow).Name = Sheets(intCurrentSheet).Name & _
                                                           "_" & Chr(intCurrentSheet + 63) & _
                                                           Chr(intCurrentSheet + 63) & _
                                                           Chr(intCurrentSheet + 63)
    Sheets(intCurrentSheet).Visible = False

Next intCurrentSheet

End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.