Help with adding columns to a code

keithb

New Member
Joined
Oct 29, 2008
Messages
42
I had a code made for me years ago and I need to make a modification to it but cannot figure out how to make it work. I am not proficient in VBA.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I have spread sheets that I fill with data based on daily sales, this code pulls certain data from these sheets and places it into a master sheet.<o:p></o:p>
I need to add 2 more columns to the extraction process.<o:p></o:p>
Can someone modify this code for me?<o:p></o:p>
This would be greatly appreciated.
Keith
<o:p></o:p>
<o:p>Private Sub Worksheet_Activate()</o:p>
<o:p>Dim mpSheet As Worksheet
Dim mpPodium As String
Dim mpLastRow As Long
Dim mpNextRow As Long
Dim mpFormulae(1 To 9) As String
Dim i As Long, j As Long, k As Long</o:p>
<o:p>mpNextRow = 2

mpFormulae(1) = "=SUM(RC[-1]*0%,RC[-2]*3%)"
mpFormulae(2) = "=SUM(RC[-2]*0%,RC[-3]*4%)"
mpFormulae(3) = "=SUM(RC[-4] * IF(RC[-3] < 5599, 3.5%, 5.5%))"
mpFormulae(4) = "=SUM(RC[-5] * IF(RC[-4] < 5599, 3.5%, 5.5%))"
mpFormulae(5) = "=SUM(RC[-6]*.5%)"
mpFormulae(6) = "=SUM(RC[-7]*.5%)"
mpFormulae(7) = "=SUM(RC[-8]*.5%)"
mpFormulae(8) = "=SUM(RC[-9]*.0%)"
mpFormulae(9) = "=SUM(RC[-10]*.0%)"</o:p>
<o:p>mpLastRow = Me.Cells(Me.Rows.Count, "L").End(xlUp).Row
Me.Range("A2").Resize(mpLastRow, 20).ClearContents
Me.Range("A2").Value = Date

For Each mpSheet In Worksheets(Array( _
"Monday", "Tuesday", "Wednesday", _
"Thursday", "Friday", "Saturday", _
"Sunday"))

With mpSheet
For i = 9 To 68 Step 10

mpPodium = .Cells(i, "C").Value
For j = 2 To 8

If .Cells(i + j, "B").Value <> "" Then

.Cells(i + j, "B").Resize(, 9).Copy
Me.Cells(mpNextRow, "A").Value = .Range("I8").Value
Me.Cells(mpNextRow, "B").Value = mpPodium
Me.Cells(mpNextRow, "C").PasteSpecial Paste:=xlPasteValues
For k = 1 To 9

Me.Cells(mpNextRow, k + 11).FormulaR1C1 = mpFormulae(k)
Next k
mpNextRow = mpNextRow + 1
End If
Next j
Next i
End With

Me.Range("L2").Resize(mpNextRow - 1, 9).NumberFormat = "#,##0.00\ "

Next mpSheet
End Sub</o:p>
<o:p>
</o:p>
<o:p></o:p>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Keith,

I'm not sure I interpreted your needing to add 2 columns correctly.
It looks like the existing code copies 9 columns from each worksheet, then adds 9 columns of formulas. I assumed you want to copy 11 columns and add 11 columns of formulas. If that is right, you'll need to define what those extra 2 formulas do.

Try this and let me know if it does what you wanted.

Rich (BB code):
Private Sub Worksheet_Activate()
    Dim mpSheet As Worksheet
    Dim mpPodium As String
    Dim mpLastRow As Long
    Dim mpNextRow As Long
    Dim mpFormulae(1 To 11) As String 
    Dim i As Long, j As Long, k As Long
    Application.ScreenUpdating = False 'runs faster
    mpNextRow = 2
 
    mpFormulae(1) = "=SUM(RC[-1]*0%,RC[-2]*3%)"
    mpFormulae(2) = "=SUM(RC[-2]*0%,RC[-3]*4%)"
    mpFormulae(3) = "=SUM(RC[-4] * IF(RC[-3] < 5599, 3.5%, 5.5%))"
    mpFormulae(4) = "=SUM(RC[-5] * IF(RC[-4] < 5599, 3.5%, 5.5%))"
    mpFormulae(5) = "=SUM(RC[-6]*.5%)"
    mpFormulae(6) = "=SUM(RC[-7]*.5%)"
    mpFormulae(7) = "=SUM(RC[-8]*.5%)"
    mpFormulae(8) = "=SUM(RC[-9]*.0%)"
    mpFormulae(9) = "=SUM(RC[-10]*.0%)"
   mpFormulae(10) = "=SUM(RC[-11]*.0%)" 'revise formulae
    mpFormulae(11) = "=SUM(RC[-12]*.0%)" 'revise formulae
    mpLastRow = Me.Cells(Me.Rows.Count, "L").End(xlUp).row
    Me.Range("A2").Resize(mpLastRow, 24).ClearContents 'edit 20->24
    Me.Range("A2").value = Date
 
    For Each mpSheet In Worksheets(Array( _
        "Monday", "Tuesday", "Wednesday", _
        "Thursday", "Friday", "Saturday", _
        "Sunday"))
 
        With mpSheet
            For i = 9 To 68 Step 10
                mpPodium = .Cells(i, "C").value
                For j = 2 To 8
                    If .Cells(i + j, "B").value <> "" Then
                        .Cells(i + j, "B").Resize(, 11).Copy 
                        Me.Cells(mpNextRow, "A").value = .Range("I8").value
                        Me.Cells(mpNextRow, "B").value = mpPodium
                        Me.Cells(mpNextRow, "C").PasteSpecial Paste:=xlPasteValues
                        For k = 1 To 11
                            Me.Cells(mpNextRow, k + 13).FormulaR1C1 = mpFormulae(k) 
                        Next k
                        mpNextRow = mpNextRow + 1
                    End If
                Next j
            Next i
        End With
        Me.Range("N2").Resize(mpNextRow - 1, 11).NumberFormat = "#,##0.00\ " 
    Next mpSheet
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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