This is my main macro (above) and in this macro I have used some macros which are shown below.Sub Macro1() ' ' Macro1 Macro ' ' Columns("A:A").Select Selection.Delete Shift:=xlToLeft Rows("1:1").Select Selection.Delete Shift:=xlUp Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1" Range("D1").Select ActiveCell.FormulaR1C1 = "=IF(RC[-2]=R1C2,RC[-1],IF(RC[-2]=R3C2,RC[-1],0))" Range("D1").Select Selection.AutoFill Destination:=Range("D1:D44160") Range("D1:D44160").Select Selection.Copy Columns("C:C").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Columns("D:D").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows2" Application.Run "'ASX Closing Prices.xlsm'!x" Application.Run "'ASX Closing Prices.xlsm'!x" Range("D1").Select ActiveCell.FormulaR1C1 = "=(RC[-1]-R[1]C[-1])/R[1]C[-1]" Range("D1:D2").Select Selection.AutoFill Destination:=Range("D1:D27632") Range("D1:D27632").Select Selection.Copy Columns("D:D").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Columns("B:C").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows3" Columns("B:B").Select Selection.Style = "Percent" Columns("A:B").Select ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range( _ "B1:B56142"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets("Sheet2").Sort .SetRange Range("A1:B56142") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub
I want to merge these two macros to create one macro, because at the moment I am creating a macro to run a macro - I was wondering if I could get the macro of the macros I am running and put it in my main macro
Sub DeleteBlankARows1() With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With End Sub Sub DeleteBlankARows2() With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "0" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With End Sub Sub DeleteBlankARows3() With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1 If Cells(r, 1) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With End Sub Sub x() Dim rng1 As Variant, rng2 As Variant, totalRng As Variant, cell As Variant Set rng1 = Worksheets("Sheet2").Range("B1") Set rng2 = rng1.End(xlDown) Set totalRng = Range(rng1, rng2) For Each cell In totalRng If cell.Value = cell.Offset(1, 0).Value Then cell.Rows.EntireRow.Delete Shift:=xlUp End If Next cell End Sub
Last edited by drmix; 11-18-2010 at 11:07 PM.
Hi drmix
You don't give us a lot to work with. You can insert this line of code in Macro1 anywhere you wishand it will execute the procedure DeleteBlankARows1 then return to Sub Macro1 at the point it was interrupted.Call DeleteBlankARows1
Is this your issue?
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
I have updated my explanation (see above)
Hi drmix
It's late here and I'm going to bed. However I'll be happy to revisit this issue in the AM. In the meantime, please look at this link http://www.oaltd.co.uk/Indenter/Default.htm it'll help the readability of your code.
Also, in my opinion, keeping your code compartmentalized is a good approach. Calling procedures to do specific tasks works for me.
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
cool thanks
basically i want to replacewithApplication.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1"etc...Sub DeleteBlankARows1() With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With End Sub
Is the DeleteBlankARows1 macro in the same workbook?
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Hi drmix
I feel as if I'm missing the point of your question. However, if the answer to RoyUK's question is affirmative, then you can simply replace the line of code as follows:The above would be my preference. However, if you only want one macro, you could modify the code as follows:' Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1" Call DeleteBlankARows1As I said, I feel I'm off point.' Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1" With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Mmm - thanks but yes I think this is not what I was after
Let me try and clarify:
Currently the macro call "macro1" is my main macro. And in this macro I have "called" 4 other marcos called "DeleteBlankARows1", "DeleteBlankARows2" etc.
The end result is that I do not want "macro1" to call the other 4 macros but have them embedded in "macro1".
Is that possible? Hope that helps
(Because if I run "macro1" in a new worksheet without the other 4 macros it stuffs up)
Hi drmix
I'm still not clear on your question UNLESS you're asking if you can do thisIf that's what you're asking, in a word "No", to the best of my knowledge (admittedly limited), can't be done. You can "Call" the procedure but cannot "Embed" the entire procedure. You cannot haveOption Explicit Sub Macro1() ' ' Macro1 Macro ' ' Columns("A:A").Select Selection.Delete Shift:=xlToLeft Rows("1:1").Select Selection.Delete Shift:=xlUp Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1" Range("D1").Select ' ActiveCell.FormulaR1C1 = "=IF(RC[-2]=R1C2,RC[-1],IF(RC[-2]=R3C2,RC[-1],0))" Sub DeleteBlankARows1() With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With End Sub Range("D1").Select Selection.AutoFill Destination:=Range("D1:D44160") Range("D1:D44160").Select Selection.Copy Columns("C:C").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Columns("D:D").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows2" Application.Run "'ASX Closing Prices.xlsm'!x" Application.Run "'ASX Closing Prices.xlsm'!x" Range("D1").Select ActiveCell.FormulaR1C1 = "=(RC[-1]-R[1]C[-1])/R[1]C[-1]" Range("D1:D2").Select Selection.AutoFill Destination:=Range("D1:D27632") Range("D1:D27632").Select Selection.Copy Columns("D:D").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Columns("B:C").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows3" Columns("B:B").Select Selection.Style = "Percent" Columns("A:B").Select ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range( _ "B1:B56142"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets("Sheet2").Sort .SetRange Range("A1:B56142") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Subinside another procedure. Sorry if I was misunderstanding your question.Sub DeleteBlankARows1() 'Your Code End Sub
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
mmm... I was wondering if
could be replaced with this - and if not why not?Sub Macro1() ' Macro1 Macro Columns("A:A").Select Selection.Delete Shift:=xlToLeft Rows("1:1").Select Selection.Delete Shift:=xlUp Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1" ... End sub
Sub Macro1() ' Macro1 Macro Columns("A:A").Select Selection.Delete Shift:=xlToLeft Rows("1:1").Select Selection.Delete Shift:=xlUp With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With ... End sub
Hi drmix
I believe that's what I suggested hereReplacing this line of code (notice that it's commented out)' Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1" With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End Withwith this' Application.Run "'ASX Closing Prices.xlsm'!DeleteBlankARows1"I must be missing something terribly here and I apologize for that...we don't appear to be communicating.With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
awesome! i didnt see the commented out,
however when i do this for the two 3 macros - there is an error - something to do with "dim r as long" do you know how to fix?
Hi drmix
I REALLY DON"T LIKE working on code I can't test. Having said that, comment out this line of codein theDim r As Longand see what happens.two 3 macros
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hi drmix
To help us help you refer to the error message. For example, you probably received a messgae like "Duplicate Declaration...". Refer to the error message so we know what's happening. This dosen't helpJohnsomething to do with "dim r as long"
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hi all thankyou for your patience - so I have put in the codes and this is the error i get
Compile error: Dupliate declaration in current scopeSub Macro1() ' ' Macro1 Macro ' ' Columns("A:A").Select Selection.Delete Shift:=xlToLeft Rows("1:1").Select Selection.Delete Shift:=xlUp On Error Resume Next Range("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete Range("D1").Select ActiveCell.FormulaR1C1 = "=IF(RC[-2]=R1C2,RC[-1],IF(RC[-2]=R3C2,RC[-1],0))" Range("D1").Select Selection.AutoFill Destination:=Range("D1:D44160") Range("D1:D44160").Select Selection.Copy Columns("C:C").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Columns("D:D").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 3).End(xlUp).Row To 1 Step -1 If Cells(r, 3) = "0" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With Dim rng1 As Variant, rng2 As Variant, totalRng As Variant, cell As Variant Set rng1 = Worksheets("Sheet2").Range("B1") Set rng2 = rng1.End(xlDown) Set totalRng = Range(rng1, rng2) For Each cell In totalRng If cell.Value = cell.Offset(1, 0).Value Then cell.Rows.EntireRow.Delete Shift:=xlUp End If Next cell Dim rng1 As Variant, rng2 As Variant, totalRng As Variant, cell As Variant Set rng1 = Worksheets("Sheet2").Range("B1") Set rng2 = rng1.End(xlDown) Set totalRng = Range(rng1, rng2) For Each cell In totalRng If cell.Value = cell.Offset(1, 0).Value Then cell.Rows.EntireRow.Delete Shift:=xlUp End If Next cell Range("D1").Select ActiveCell.FormulaR1C1 = "=(RC[-1]-R[1]C[-1])/R[1]C[-1]" Range("D1:D2").Select Selection.AutoFill Destination:=Range("D1:D27632") Range("D1:D27632").Select Selection.Copy Columns("D:D").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Columns("B:C").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft With Application .Calculation = xlCalculationManual .ScreenUpdating = False Dim r As Long For r = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1 If Cells(r, 1) = "" Then Rows(r).Delete Next r .Calculation = xlCalculationAutomatic .ScreenUpdating = True End With Columns("B:B").Select Selection.Style = "Percent" Columns("A:B").Select ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range( _ "B1:B56142"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets("Sheet2").Sort .SetRange Range("A1:B56142") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub
I have also attached my worksheet - hope this helps! =]
Last edited by drmix; 11-18-2010 at 09:44 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks