Simple Macro help

E

Ewing25

Heres what i want the macro to do.

I have a spreadsheet with 2 tabs. one named commisions and the other named
summary.

In the commisions tab there are 4 columns (Lets call them 1,2,3, and 4)
Columns 1 and 2 are non number values and 3 and 4 are columns with number
values.

At every change in Column 2 i want it to put the value next to it in column
1 and the sum of the values in columns 3 and 4 that correlate with the value
in Column2.

And i want it to display the information in the Summary Tab.

If anyone can help that would be amazing.

Thanks!
Alex
 
B

Bob Phillips

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "B:B" '<== change to suit
Dim sh As Worksheet
Dim NextRow As Long

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

Set sh = Worksheets("Sheet1")
If sh.Range("A1").Value = "" Then

NextRow = 1
ElseIf sh.Range("A2").Value = "" Then

NextRow = 2
Else

NextRow = sh.Range("a1").End(xlDown).Row + 1
End If

.Offset(0, -1).Copy sh.Cells(NextRow, "A")
sh.Cells(NextRow, "B").Value = .Offset(0, 1).Value + .Offset(0,
2).Value
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
E

Ewing25

It keeps telling me to create a name and when i do it starts a new sub. in a
module.

Not sure what to do.
 
B

Bob Phillips

I have no idea what is going on, it didn't here.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
E

Ewing25

Does it have anything to do with the heading? the Sub name. I have no idea
why its doing this.
 
B

Bob Phillips

What heading?

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top