+ Reply to Thread
Results 1 to 7 of 7

Run macro independent of cell

  1. #1
    Registered User
    Join Date
    04-07-2014
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Run macro independent of cell

    Hi,

    I recently recorded a macro for multiplication and sorting 12 rows in excel. But when the no. of rows are increased the macro still runs only for first 12 rows. How to solve this problem?
    I want my macro to count the no. of rows first and run for all the data even if the no. of rows are less than or greater than 12. Please help. Thanks in advance

    Thanks
    Alka

  2. #2
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Run macro independent of cell

    Please Login or Register  to view this content.
    if you want help placing it post your code
    Sub Reputation()
    Dim Problem as Variant
    Dim Reputation as Integer
    For Each Problem in Forum.Threads
        If Problem.Title = "*[Solved]*" and Solver.Name = "Leon V (AW)" Then Reputation = Reputation + 1
    Next Problem
    End Sub

  3. #3
    Registered User
    Join Date
    04-07-2014
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Post Re: Run macro independent of cell

    Hi,
    Below is the macro code. I don't want it to directly read range but instead it should count the no. of rows first and then perform the operation on all the rows. Any help in this regard is appreciated.

    Sub Alka()
    Range("D1").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -0.349986266670736
    .PatternTintAndShade = 0
    End With
    ActiveCell.FormulaR1C1 = "Consumption"
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "=RC[-2]*RC[-1]"
    Range("D2").Select
    Selection.AutoFill Destination:=Range("D2:D12"), Type:=xlFillDefault
    Range("D2:D12").Select
    Range("D13").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-11]C:R[-1]C)"
    Range("E1").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -0.349986266670736
    .PatternTintAndShade = 0
    End With
    ActiveCell.FormulaR1C1 = "Percentage"
    Range("E2").Select
    Columns("E:E").EntireColumn.AutoFit
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]/R13C4"
    Range("E2").Select
    Selection.AutoFill Destination:=Range("E2:E12"), Type:=xlFillDefault
    Range("E2:E12").Select
    Range("E13").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-11]C:R[-1]C)"
    Range("E2:E12").Select
    ActiveWorkbook.Worksheets("Sheet2-changed").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet2-changed").Sort.SortFields.Add Key:=Range( _
    "E2"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal
    Range("A2:E12").Select
    ActiveWorkbook.Worksheets("Sheet2-changed").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet2-changed").Sort.SortFields.Add Key:=Range( _
    "A2"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal
    Range("A1:E12").Select
    ActiveWorkbook.Worksheets("Sheet2-changed").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet2-changed").Sort.SortFields.Add Key:=Range( _
    "E2:E12"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet2-changed").Sort
    .SetRange Range("A1:E12")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Range("F1").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -0.349986266670736
    .PatternTintAndShade = 0
    End With
    ActiveCell.FormulaR1C1 = "cumulative"
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]"
    Range("F3").Select
    ActiveCell.FormulaR1C1 = "=R[-1]C+RC[-1]"
    Range("F3").Select
    Selection.AutoFill Destination:=Range("F3:F12"), Type:=xlFillDefault
    Range("F3:F12").Select
    Range("F2:F12").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
    Formula1:="=0", Formula2:="=0.7"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -16383844
    .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 13551615
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
    Formula1:="=0.7001", Formula2:="=0.9"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -16383844
    .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 13551615
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
    Formula1:="=0.9001", Formula2:="=1"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -16751204
    .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 10284031
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
    Formula1:="=0.7001", Formula2:="=0.9"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
    .Color = -16752384
    .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 13561798
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("I8").Select
    End Sub

  4. #4
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Run macro independent of cell

    Please use code tags in future
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-07-2014
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run macro independent of cell

    Hi,

    Sorry I was not aware of it before.. Will keep it in mind.. Any help in solving the problem would be appreciated. Kindly help

    Alka

  6. #6
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Run macro independent of cell

    the code above has had usedrange limits put into it, along with some clean up.

  7. #7
    Registered User
    Join Date
    04-07-2014
    Location
    Chennai
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run macro independent of cell

    Thank you so much Leon .. I'll check if its works for me

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Word Template for Independent Documents with Macro Buttons
    By ccsouthq in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-10-2013, 02:43 PM
  2. Making macro independent of ms excel
    By akash.add in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2012, 11:46 PM
  3. How to make a macro cell independent
    By Ads. in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-17-2011, 08:43 AM
  4. Make macro independent of position
    By Call in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2011, 11:04 AM
  5. Want a macro to run independent of cells recorded
    By jetablack4 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2009, 12:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1