View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Paul Paul is offline
external usenet poster
 
Posts: 108
Default Help with moving cells of info around.

Pikus

This is Interesting that you put this code in a
CommandButton Format. I don't think I ever have used
something like this before? Can you help me, because when
I put this code into a CommandButton from the Control
ToolBox menu I can not figure out how to activate the
macro to begin to work?

Also if I just put the code into a normal sub file I get
all sorts of errors.

Any thoughts
Paul


-----Original Message-----
Try this:

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim lrow As Long
Dim x As Long
Dim y As Long
Dim a As Long
Dim ws As Worksheet

Set ws = Worksheets(1)
lrow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count

For x = 2 To lrow
cust = ws.Cells(x, 27).Value
For y = 2 To lrow
If ws.Cells(y, 1).Value = cust Then
ws.Range(ws.Cells(x, 27), ws.Cells(x, 30)).Cut
ws.Cells(y, 31).Select
ActiveSheet.Paste
End If
Next y
Next x
ws.Range(ws.Cells(1, 27), ws.Cells(1, 30)).Cut
ws.Cells(1, 31).Select
ActiveSheet.Paste
a = 1
For x = 2 To lrow
If ws.Cells(x, 27).Value < "" Then
ws.Range(ws.Cells(x, 27), ws.Cells(x, 30)).Cut
ws.Cells(lrow + a, 31).Select
ActiveSheet.Paste
a = a + 1
End If
Next x
For x = 1 To 4
ws.Columns(27).Delete
Next x
Application.Goto ws.Cells(1, 1)
Application.ScreenUpdating = True
End Sub

- Pikus


---
Message posted from http://www.ExcelForum.com/

.