ActiveCell other sheet

stella3000

New Member
Joined
Aug 16, 2009
Messages
3
I’ve created the following macro (relative reference) and assigned it to a button in order to be applied on the first sheet (= “Jan”) :<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

Sub IP_III()
'
' IP_III Macro
' Macro recorded 18/08/2009 by brutsaj
'
'
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Copy
Selection.Insert Shift:=xlDown
ActiveCell.Offset(0, 3).Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "n"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "n"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "n"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "n"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "n"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "0"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "0"
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveCell.FormulaR1C1 = "0"
ActiveCell.Offset(0, 3).Range("A1").Select
ActiveCell.Offset(0, -127).Range("A1:DI1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
ActiveCell.Offset(0, -2).Range("A1").Select
Selection.Font.Italic = True
ActiveCell.FormulaR1C1 = "Insert Post Name"
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub

I have a workbook that contains multiple sheets (for each month the same one) with exactly the same content. I want this macro to automatically be applied to the other sheets on the exact same location of the active cell on the first sheet.


How do I translate this to VBA code?<o:p></o:p>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
A worksheet doesn't have an ActiveCell property.

What do you actually want to do with this code?

You might be able to replace the first part of the code with this.
Code:
'
With ActiveCell.Rows("1:1").EntireRow
    .Copy
    .Insert Shift:=xlDown
End With
ActiveCell.Offset(0, 3) = "n"
ActiveCell.Offset(0, 4) = "n"
ActiveCell.Offset(0, 5) = "n"
ActiveCell.Offset(0, 6) = "n"
ActiveCell.Offset(0, 7) = "n"
ActiveCell.Offset(0, 11) = "0"
ActiveCell.Offset(0, 15) = "0"
ActiveCell.Offset(0, 19) = "0"
Note I said 'might' and haven't dealt with the rest of the code.

The reason for that is it's pretty hard to follow what the code is actually meant to do with all the ActiveCell, Offset, Select etc.:)
 
Upvote 0
Thank you for your reply, Norie!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
But just ignore my macro from above. If you have 12 exactly the same sheets with exactly the same content and you want to create a macro that does the same actions (copy, insert, ...) in the active sheet, scope = based on the active/selected row, to the other 11 sheets...How would you do that? <o:p></o:p>
<o:p></o:p>
I just have trouble to create this macro because I don't have an absolute address from a cell to refer to because it's variable/ it depends on what cell is active. The actions aren't variable so these I can program, but not the location on which the actions should be applied on.<o:p></o:p>
<o:p></o:p>
Man, it’s difficult to explain this! :)
 
Upvote 0
Well if you want to cycle through all the worksheets in a workbook you could use something like this.
Code:
For Each ws In ThisWorkbook.Worksheets
     ws.Range("A1") = ws.Name
     ' all sorts of other code here
Next ws
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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