#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 70
Default CPSCount

Here is the code I currently have.

Sub CPSCount()

Columns("B:C").Select
Selection.Copy
Sheets.Add
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Sheet3"
Range("A1").Select
ActiveSheet.Paste
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Range("C1").Select
ActiveCell.FormulaR1C1 = "MP11"
Range("D1").Select
ActiveCell.FormulaR1C1 = "MP12"
Range("E1").Select
ActiveCell.FormulaR1C1 = "MP20"

This is what my code currently does€¦

Sheet 1 copy columns B:C

Insert new worksheet (Sheet3)

Paste contents into new worksheet (Sheet3) starting in cell A1

Insert row above Row 1

In cell C1 type MP11, in cell D1 type MP12, and in cell E1 type MP20

These are the additional steps I would like my code to take€¦

Every cell in Column B has either MP11, MP12, or MP20, while every cell in
Column A has a 7 digit number, so the contents of Column A and Column B
belong together.

I want to keep a tally/count of how many times each seven digit number
appears in MP11, MP12, and MP20. In other words, I want to create a code
that will look at the number in Column A then look for MP11, MP12, or MP20 in
Column B. If Column B says MP11 then increase Column C by 1 in the same row,
if Column B says MP12 then increase Column D by 1 in the same row, if Column
B says MP20 then increase Column E by 1 in the same row. Sometimes the seven
digit number in Column A will be repeated. When that happens I want to
delete the row where the duplicate(s) appear(s) but increase the count in
Column C, D, or E (depending on the contents in Column B) by 1.

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 857
Default CPSCount

Hi,

And the next time you enter a number in A1 do you want the value in A5 to be
increased by this amount or do you want the value adjusted by the difference
between the old value in A1 and then new value in A1?

If the first, then you will need to write a VBA macro.


Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Set isect = Application.Intersect(Target, [A1])
If Not isect Is Nothing Then
[A5] = [A5] + [A1]
End If
End Sub

If the second then in A5

=A1+InitialValueOfA5

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"MCheru" wrote:

Here is the code I currently have.

Sub CPSCount()

Columns("B:C").Select
Selection.Copy
Sheets.Add
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Sheet3"
Range("A1").Select
ActiveSheet.Paste
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Range("C1").Select
ActiveCell.FormulaR1C1 = "MP11"
Range("D1").Select
ActiveCell.FormulaR1C1 = "MP12"
Range("E1").Select
ActiveCell.FormulaR1C1 = "MP20"

This is what my code currently does€¦

Sheet 1 copy columns B:C

Insert new worksheet (Sheet3)

Paste contents into new worksheet (Sheet3) starting in cell A1

Insert row above Row 1

In cell C1 type MP11, in cell D1 type MP12, and in cell E1 type MP20

These are the additional steps I would like my code to take€¦

Every cell in Column B has either MP11, MP12, or MP20, while every cell in
Column A has a 7 digit number, so the contents of Column A and Column B
belong together.

I want to keep a tally/count of how many times each seven digit number
appears in MP11, MP12, and MP20. In other words, I want to create a code
that will look at the number in Column A then look for MP11, MP12, or MP20 in
Column B. If Column B says MP11 then increase Column C by 1 in the same row,
if Column B says MP12 then increase Column D by 1 in the same row, if Column
B says MP20 then increase Column E by 1 in the same row. Sometimes the seven
digit number in Column A will be repeated. When that happens I want to
delete the row where the duplicate(s) appear(s) but increase the count in
Column C, D, or E (depending on the contents in Column B) by 1.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 70
Default CPSCount

I wanted the next time I entered a number in A1 the value in A5 to be
increased by this amount and that's what happened. Thanks so much for you're
help. The macro is great!

"Shane Devenshire" wrote:

Hi,

And the next time you enter a number in A1 do you want the value in A5 to be
increased by this amount or do you want the value adjusted by the difference
between the old value in A1 and then new value in A1?

If the first, then you will need to write a VBA macro.


Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Set isect = Application.Intersect(Target, [A1])
If Not isect Is Nothing Then
[A5] = [A5] + [A1]
End If
End Sub

If the second then in A5

=A1+InitialValueOfA5

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"MCheru" wrote:

Here is the code I currently have.

Sub CPSCount()

Columns("B:C").Select
Selection.Copy
Sheets.Add
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "Sheet3"
Range("A1").Select
ActiveSheet.Paste
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Range("C1").Select
ActiveCell.FormulaR1C1 = "MP11"
Range("D1").Select
ActiveCell.FormulaR1C1 = "MP12"
Range("E1").Select
ActiveCell.FormulaR1C1 = "MP20"

This is what my code currently does€¦

Sheet 1 copy columns B:C

Insert new worksheet (Sheet3)

Paste contents into new worksheet (Sheet3) starting in cell A1

Insert row above Row 1

In cell C1 type MP11, in cell D1 type MP12, and in cell E1 type MP20

These are the additional steps I would like my code to take€¦

Every cell in Column B has either MP11, MP12, or MP20, while every cell in
Column A has a 7 digit number, so the contents of Column A and Column B
belong together.

I want to keep a tally/count of how many times each seven digit number
appears in MP11, MP12, and MP20. In other words, I want to create a code
that will look at the number in Column A then look for MP11, MP12, or MP20 in
Column B. If Column B says MP11 then increase Column C by 1 in the same row,
if Column B says MP12 then increase Column D by 1 in the same row, if Column
B says MP20 then increase Column E by 1 in the same row. Sometimes the seven
digit number in Column A will be repeated. When that happens I want to
delete the row where the duplicate(s) appear(s) but increase the count in
Column C, D, or E (depending on the contents in Column B) by 1.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"