Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row below once data is copied above

Hi there,
Can someone help me, I have a problem in that i have a range of data with
part numbers down column A, with various data in columnsB,C,D. The part
numbers could appear one or more times, what i want to do is detailed below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA 50

EXCEL:AFTER
A B C D E
1 ABA 20 50 10 50

regards Harry


  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Delete row below once data is copied above

Try this. Select your entire data list (including a single field name row)
and run this procedure. It outputs the new data a few rows below the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d + 1) =
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2, Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2, Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of data with
part numbers down column A, with various data in columnsB,C,D. The part
numbers could appear one or more times, what i want to do is detailed below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA 50

EXCEL:AFTER
A B C D E
1 ABA 20 50 10 50

regards Harry



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row below once data is copied above

Hi Jay,

the code looks promising, however when i run it I keep getting a compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field name
row)
and run this procedure. It outputs the new data a few rows below the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d + 1) =
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2, Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of data with
part numbers down column A, with various data in columnsB,C,D. The part
numbers could appear one or more times, what i want to do is detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA 50

EXCEL:AFTER
A B C D E
1 ABA 20 50 10 50

regards Harry





  #4   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Delete row below once data is copied above

So very sorry, Harry. I had to step out unexpectedly. I'll take a look at
this right now...
--
Jay


"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field name
row)
and run this procedure. It outputs the new data a few rows below the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d + 1) =
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2, Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of data with
part numbers down column A, with various data in columnsB,C,D. The part
numbers could appear one or more times, what i want to do is detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA 50

EXCEL:AFTER
A B C D E
1 ABA 20 50 10 50

regards Harry






  #5   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Delete row below once data is copied above

Hi Harry -

I can't duplicate the error you describe. So check the following:

1. Make sure you have the data range selected before you run the procudure.

2. During the failed compile, does VBA highlight any suspected statements ?
If so, which one(s) ?

3. What version of Excel do you have ?

I'll continue working on a more universal (environment-independent) version,
but it would help to know about the 3 items above.

Jay

"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field name
row)
and run this procedure. It outputs the new data a few rows below the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d + 1) =
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2, Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of data with
part numbers down column A, with various data in columnsB,C,D. The part
numbers could appear one or more times, what i want to do is detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA 50

EXCEL:AFTER
A B C D E
1 ABA 20 50 10 50

regards Harry








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row below once data is copied above

Hi Jay
1. I am selecting the range
2.variable not defined error, for the following: Rng,
Rng2,pn,pc,upn,i,data,d
3. Excel xp (I think its 2003)

"Jay" wrote in message
...
Hi Harry -

I can't duplicate the error you describe. So check the following:

1. Make sure you have the data range selected before you run the
procudure.

2. During the failed compile, does VBA highlight any suspected statements
?
If so, which one(s) ?

3. What version of Excel do you have ?

I'll continue working on a more universal (environment-independent)
version,
but it would help to know about the 3 items above.

Jay

"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field name
row)
and run this procedure. It outputs the new data a few rows below the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d + 1)
=
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of data
with
part numbers down column A, with various data in columnsB,C,D. The
part
numbers could appear one or more times, what i want to do is detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D
E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA
50

EXCEL:AFTER
A B C D
E
1 ABA 20 50 10 50

regards Harry








  #7   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Delete row below once data is copied above

Look for the line "Option Explicit" at or near the top of the module and
temporarily delete it or disable it by preceeding it with a single quotation
mark ('). Then run the code again.

If Option Explicit is not present, let me know.
--
Jay


"Big H" wrote:

Hi Jay
1. I am selecting the range
2.variable not defined error, for the following: Rng,
Rng2,pn,pc,upn,i,data,d
3. Excel xp (I think its 2003)

"Jay" wrote in message
...
Hi Harry -

I can't duplicate the error you describe. So check the following:

1. Make sure you have the data range selected before you run the
procudure.

2. During the failed compile, does VBA highlight any suspected statements
?
If so, which one(s) ?

3. What version of Excel do you have ?

I'll continue working on a more universal (environment-independent)
version,
but it would help to know about the 3 items above.

Jay

"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field name
row)
and run this procedure. It outputs the new data a few rows below the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d + 1)
=
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of data
with
part numbers down column A, with various data in columnsB,C,D. The
part
numbers could appear one or more times, what i want to do is detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D
E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA
50

EXCEL:AFTER
A B C D
E
1 ABA 20 50 10 50

regards Harry









  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row below once data is copied above

Jay,

It works perfect thanks. Why does it not work when option explicit is on?
regards from Scotland

"Jay" wrote in message
...
Look for the line "Option Explicit" at or near the top of the module and
temporarily delete it or disable it by preceeding it with a single
quotation
mark ('). Then run the code again.

If Option Explicit is not present, let me know.
--
Jay


"Big H" wrote:

Hi Jay
1. I am selecting the range
2.variable not defined error, for the following: Rng,
Rng2,pn,pc,upn,i,data,d
3. Excel xp (I think its 2003)

"Jay" wrote in message
...
Hi Harry -

I can't duplicate the error you describe. So check the following:

1. Make sure you have the data range selected before you run the
procudure.

2. During the failed compile, does VBA highlight any suspected
statements
?
If so, which one(s) ?

3. What version of Excel do you have ?

I'll continue working on a more universal (environment-independent)
version,
but it would help to know about the 3 items above.

Jay

"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a
compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field
name
row)
and run this procedure. It outputs the new data a few rows below
the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array
cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d +
1)
=
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of
data
with
part numbers down column A, with various data in columnsB,C,D. The
part
numbers could appear one or more times, what i want to do is
detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D
E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA
50

EXCEL:AFTER
A B C D
E
1 ABA 20 50 10 50

regards Harry











  #9   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Delete row below once data is copied above

Excellent -

An Option Explicit statement keeps spelling errors from creating problems in
code by forcing discipline on the programmer. With Option Explicit, a
program won't run unless a variable that is used in the code is also declared
at the start of the procedure, e.g., Dim var1 as range.

Now, if all of your variables are declared (that is, rigourously 'defined'),
then if you accidentally type 'vaar1' instead of 'var1' ("vaar1 =
cells(1,7)") deep in the bowels of your program, excel will not run the
program, but will give you the warning that you received ("variable not
defined). If Option Explicit is NOT set in this example, VB would assign a
cells(1,7) to vaar1 and var1 would have no value - although the programmer
would think that var1 was assigned the range cells (1,7).

That will create a whole bunch of problems later in programming if you're
assuming one thing when it it not the case. The sentinal protects you from
this.

Note though, that this forces a different programming style. In a rapid
application development environment like VBA, most of us don't know what
variables we'll be using until we start programming. So, it's often
programmer's choice as to whether it is used.

Have a great day, Scotland,
--

Jay (Alaska, USA)


"Big H" wrote:

Jay,

It works perfect thanks. Why does it not work when option explicit is on?
regards from Scotland

"Jay" wrote in message
...
Look for the line "Option Explicit" at or near the top of the module and
temporarily delete it or disable it by preceeding it with a single
quotation
mark ('). Then run the code again.

If Option Explicit is not present, let me know.
--
Jay


"Big H" wrote:

Hi Jay
1. I am selecting the range
2.variable not defined error, for the following: Rng,
Rng2,pn,pc,upn,i,data,d
3. Excel xp (I think its 2003)

"Jay" wrote in message
...
Hi Harry -

I can't duplicate the error you describe. So check the following:

1. Make sure you have the data range selected before you run the
procudure.

2. During the failed compile, does VBA highlight any suspected
statements
?
If so, which one(s) ?

3. What version of Excel do you have ?

I'll continue working on a more universal (environment-independent)
version,
but it would help to know about the 3 items above.

Jay

"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a
compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field
name
row)
and run this procedure. It outputs the new data a few rows below
the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array
cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i = 0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i, d +
1)
=
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of
data
with
part numbers down column A, with various data in columnsB,C,D. The
part
numbers could appear one or more times, what i want to do is
detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D
E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA
50

EXCEL:AFTER
A B C D
E
1 ABA 20 50 10 50

regards Harry












  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row below once data is copied above

Jay,
sorry for being a nuisance, can you tell me what paramaters i would change
if i wanted to include more columns. As most times I would use more columns
than the example I have given.

regards Harry

"Jay" wrote in message
...
Excellent -

An Option Explicit statement keeps spelling errors from creating problems
in
code by forcing discipline on the programmer. With Option Explicit, a
program won't run unless a variable that is used in the code is also
declared
at the start of the procedure, e.g., Dim var1 as range.

Now, if all of your variables are declared (that is, rigourously
'defined'),
then if you accidentally type 'vaar1' instead of 'var1' ("vaar1 =
cells(1,7)") deep in the bowels of your program, excel will not run the
program, but will give you the warning that you received ("variable not
defined). If Option Explicit is NOT set in this example, VB would assign
a
cells(1,7) to vaar1 and var1 would have no value - although the programmer
would think that var1 was assigned the range cells (1,7).

That will create a whole bunch of problems later in programming if you're
assuming one thing when it it not the case. The sentinal protects you
from
this.

Note though, that this forces a different programming style. In a rapid
application development environment like VBA, most of us don't know what
variables we'll be using until we start programming. So, it's often
programmer's choice as to whether it is used.

Have a great day, Scotland,
--

Jay (Alaska, USA)


"Big H" wrote:

Jay,

It works perfect thanks. Why does it not work when option explicit is on?
regards from Scotland

"Jay" wrote in message
...
Look for the line "Option Explicit" at or near the top of the module
and
temporarily delete it or disable it by preceeding it with a single
quotation
mark ('). Then run the code again.

If Option Explicit is not present, let me know.
--
Jay


"Big H" wrote:

Hi Jay
1. I am selecting the range
2.variable not defined error, for the following: Rng,
Rng2,pn,pc,upn,i,data,d
3. Excel xp (I think its 2003)

"Jay" wrote in message
...
Hi Harry -

I can't duplicate the error you describe. So check the following:

1. Make sure you have the data range selected before you run the
procudure.

2. During the failed compile, does VBA highlight any suspected
statements
?
If so, which one(s) ?

3. What version of Excel do you have ?

I'll continue working on a more universal (environment-independent)
version,
but it would help to know about the 3 items above.

Jay

"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a
compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field
name
row)
and run this procedure. It outputs the new data a few rows below
the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array
cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i =
0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i,
d +
1)
=
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of
data
with
part numbers down column A, with various data in columnsB,C,D.
The
part
numbers could appear one or more times, what i want to do is
detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D
E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA
50

EXCEL:AFTER
A B C D
E
1 ABA 20 50 10
50

regards Harry
















  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Delete row below once data is copied above

Jay,
sorry for being a nuisance, can you tell me what paramaters i would change
if i wanted to include more columns. As most times I would use more columns
than the example I have given.

regards Harry

"Jay" wrote in message
...
Excellent -

An Option Explicit statement keeps spelling errors from creating problems
in
code by forcing discipline on the programmer. With Option Explicit, a
program won't run unless a variable that is used in the code is also
declared
at the start of the procedure, e.g., Dim var1 as range.

Now, if all of your variables are declared (that is, rigourously
'defined'),
then if you accidentally type 'vaar1' instead of 'var1' ("vaar1 =
cells(1,7)") deep in the bowels of your program, excel will not run the
program, but will give you the warning that you received ("variable not
defined). If Option Explicit is NOT set in this example, VB would assign
a
cells(1,7) to vaar1 and var1 would have no value - although the programmer
would think that var1 was assigned the range cells (1,7).

That will create a whole bunch of problems later in programming if you're
assuming one thing when it it not the case. The sentinal protects you
from
this.

Note though, that this forces a different programming style. In a rapid
application development environment like VBA, most of us don't know what
variables we'll be using until we start programming. So, it's often
programmer's choice as to whether it is used.

Have a great day, Scotland,
--

Jay (Alaska, USA)


"Big H" wrote:

Jay,

It works perfect thanks. Why does it not work when option explicit is on?
regards from Scotland

"Jay" wrote in message
...
Look for the line "Option Explicit" at or near the top of the module
and
temporarily delete it or disable it by preceeding it with a single
quotation
mark ('). Then run the code again.

If Option Explicit is not present, let me know.
--
Jay


"Big H" wrote:

Hi Jay
1. I am selecting the range
2.variable not defined error, for the following: Rng,
Rng2,pn,pc,upn,i,data,d
3. Excel xp (I think its 2003)

"Jay" wrote in message
...
Hi Harry -

I can't duplicate the error you describe. So check the following:

1. Make sure you have the data range selected before you run the
procudure.

2. During the failed compile, does VBA highlight any suspected
statements
?
If so, which one(s) ?

3. What version of Excel do you have ?

I'll continue working on a more universal (environment-independent)
version,
but it would help to know about the 3 items above.

Jay

"Big H" wrote:

Hi Jay,

the code looks promising, however when i run it I keep getting a
compile
error saying variables not defined.
regards Harry

"Jay" wrote in message
...
Try this. Select your entire data list (including a single field
name
row)
and run this procedure. It outputs the new data a few rows below
the
existing table, so make sure you have room there....
--
Jay

Public Sub consolidatePartNumber()
'Select your data list, including the field name row,
'then run this procedure.
Dim cleanTable() As Variant
Dim partNumbers As Collection

Set Rng = Selection

If Not Rng Is Nothing Then
Set Rng2 = Rng.Columns(1)
Else
Exit Sub
End If

Set Rng2 = Rng2.Offset(1).Resize(Rng2.Rows.Count - 1)
'Set Rng2 = Rng2.SpecialCells(xlCellTypeVisible)

'Get unique part numbers
Set partNumbers = New Collection
On Error Resume Next
For Each pn In Rng2.Cells
With pn
partNumbers.Add .Value, CStr(.Value)
End With
Next 'pn
On Error GoTo 0

'Consolidate data for each part number and store in array
cleanTable
pc = partNumbers.Count: ReDim cleanTable(1 To pc, 1 To 5): i =
0
For Each upn In partNumbers
i = i + 1
cleanTable(i, 1) = upn
For Each pn In Rng2.Cells
If pn.Value = upn Then
Set data = Range(pn.Offset(0, 1), pn.Offset(0, 4))
For d = 1 To 4
If Not IsEmpty(data(1, d)) Then cleanTable(i,
d +
1)
=
data(1, d).Value
Next d
End If
Next 'pn
Next 'upn
imax = i

'Put results (cleanTable) below existing table.
Selection.Rows(1).Copy Destination:= _
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column)
Cells(Selection.Rows.Count + Selection.Row + 2,
Selection.Column).Select

For i = 1 To imax
For j = 0 To 4
ActiveCell.Offset(i, j) = cleanTable(i, j + 1)
Next j
Next i

End Sub


"Big H" wrote:

Hi there,
Can someone help me, I have a problem in that i have a range of
data
with
part numbers down column A, with various data in columnsB,C,D.
The
part
numbers could appear one or more times, what i want to do is
detailed
below.
The range extends to row 1000.


EXCEL: BEFORE
A B C D
E
1 ABA 50
2 ABA 20
3 ABA 10
4 ABA
50

EXCEL:AFTER
A B C D
E
1 ABA 20 50 10
50

regards Harry














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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copied formula produces unexpected copied results Robert New Users to Excel 1 December 5th 08 04:11 PM
Data Sort #ERR in copied data - Exel 2003 colindav Excel Discussion (Misc queries) 2 October 22nd 08 10:08 AM
Delete graphics copied from a Web page Jim Georgia Excel Discussion (Misc queries) 1 October 20th 05 02:47 PM
Delete the formulas of webpage, copied & pasted on excel sheet Mustafa Abedin Excel Discussion (Misc queries) 1 June 19th 05 02:39 PM
delete commandbuttons on copied sheet qerj Excel Programming 6 February 16th 04 01:18 PM


All times are GMT +1. The time now is 09:36 AM.

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

About Us

"It's about Microsoft Excel"