![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Dear Mr. Excel,
I have a problem with a macro I have written. Sub Start() Sheets(1).Cells(3, 1).CurrentRegion.Copy Sheets(2).Cells(6, 1).PasteSpecial xlValues Cells(6, 3).FormulaR1C1 = "=SUMIF(Kelder!C,RC[-2],Kelder!C[2])" Cells(6, 3).Copy m = ActiveSheet.UsedRange.Rows.Count For x = 6 To m Cells(x, 3).PasteSpecial Next Application.CutCopyMode = False End Sub The formula contains the word “Kelder” because that’s the name of the active sheet. If I change the name of the sheet, the macro doesn’t work anymore. The name of the sheet varies. How can I create a macro who works regardless the name of the sheet |
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
Code:
Sub Start()
Dim SheetName As String
Sheets(1).Cells(3, 1).CurrentRegion.Copy
SheetName = Sheets(1).Name
Sheets(2).Cells(6, 1).PasteSpecial xlValues
Cells(6, 3).FormulaR1C1 = "=SUMIF(" & SheetName & "!C,RC[-2]," & _
SheetName & "!C[2])"
Cells(6, 3).Copy
m = ActiveSheet.UsedRange.Rows.Count
For x = 6 To m
Cells(x, 3).PasteSpecial
Next
Application.CutCopyMode = False
End Sub
_________________ Barrie Davidson My Excel Web Page [ This Message was edited by: Barrie Davidson on 2002-02-18 05:59 ] |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|