Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello
I hope someone can help with what I think is a basic excel question . The excel version I am working with is 8.0 . I need to match two columns . COLUMN A COLUMN C ROW 1 MR-1001 ROW 2 500.00 ROW 3 MS-1002 ROW 4 ROW 5 725.25 ROW 6 MT-2004 ROW 7 ROW 8 ROW 9 ROW 10 925.00 What I need is the 500.00 in column c to be on the same row as mr-1001 which is row 1 . 725.25 needs to be in row 3 to match up with ms-1002 an finally 925.00 needs to be on row 6 to match up with mt-2004 . Nothing needs moved out of the columns they are originally in . This report was exported into excel from an accounting software program and the report is approx. 600 pages long . So hopefully someone can help me with this problem . Sincerely Mason |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub testit()
Dim i As Long, lngRows As Long, rngCell As Range With Worksheets(1) lngRows = .Cells(.Rows.Count, 3).End(xlUp).Row If .Cells(1, 1) = "" Then i = .Cells(1, 1).End(xlDown).Row Else i = 1 Do Until i lngRows If .Cells(i, 3) = "" Then Set rngCell = .Cells(i, 3).End(xlDown) .Cells(i, 3).Value = rngCell.Value rngCell.Value = "" End If i = .Cells(i, 1).End(xlDown).Row Loop End With End Sub "MASON" wrote in message om... Hello I hope someone can help with what I think is a basic excel question . The excel version I am working with is 8.0 . I need to match two columns . COLUMN A COLUMN C ROW 1 MR-1001 ROW 2 500.00 ROW 3 MS-1002 ROW 4 ROW 5 725.25 ROW 6 MT-2004 ROW 7 ROW 8 ROW 9 ROW 10 925.00 What I need is the 500.00 in column c to be on the same row as mr-1001 which is row 1 . 725.25 needs to be in row 3 to match up with ms-1002 an finally 925.00 needs to be on row 6 to match up with mt-2004 . Nothing needs moved out of the columns they are originally in . This report was exported into excel from an accounting software program and the report is approx. 600 pages long . So hopefully someone can help me with this problem . Sincerely Mason |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sort of simple, but seems to work. It assumes you have no
more thatn 20000 rows of data, which youmay need to change. Have a Merry Christmas Sub Macro1() Do Until ActiveCell.Row = 20000 If ActiveCell.Value = "" Then ActiveCell.Offset(1, 0).Range("A1").Select Else ActiveCell.Offset(0, 1).Select returncell = ActiveCell.Address Selection.End(xlDown).Select Selection.Cut Range(returncell).Select ActiveSheet.Paste ActiveCell.Offset(1, -1).Range("A1").Select End If Loop Range("A1").Select End Sub -----Original Message----- Hello I hope someone can help with what I think is a basic excel question . The excel version I am working with is 8.0 . I need to match two columns . COLUMN A COLUMN C ROW 1 MR-1001 ROW 2 500.00 ROW 3 MS-1002 ROW 4 ROW 5 725.25 ROW 6 MT-2004 ROW 7 ROW 8 ROW 9 ROW 10 925.00 What I need is the 500.00 in column c to be on the same row as mr-1001 which is row 1 . 725.25 needs to be in row 3 to match up with ms-1002 an finally 925.00 needs to be on row 6 to match up with mt-2004 . Nothing needs moved out of the columns they are originally in . This report was exported into excel from an accounting software program and the report is approx. 600 pages long . So hopefully someone can help me with this problem . Sincerely Mason . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try one of the following two options.
'Preserve spacing in Column A option Sub Test() Dim Rng1 As Range, Rng2 As Range Dim C As Range, TempAr() As String Dim i As Integer Set Rng1 = Intersect(Columns("A"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstants )) Set Rng2 = Intersect(Columns("C"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstants )) For Each C In Rng2 i = i + 1 ReDim Preserve TempAr(i) TempAr(i) = C.Value Next i = 0 For Each C In Rng1 i = i + 1 C.Offset(, 3) = C C.Offset(, 5) = TempAr(i) Next Columns("A:C").Delete End Sub 'Remove blanks in Columns A and C option Sub Test2() Dim Rng1 As Range, Rng2 As Range, C As Range Dim i As Integer Set Rng1 = Intersect(Columns("A"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstants )) Set Rng2 = Intersect(Columns("C"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstants )) For Each C In Rng1 i = i + 1 Cells(i, 4) = C Next Regards, Greg |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I did a sloppy copy and paste. Macro Test2 should be:
Sub Test2() Dim Rng1 As Range, Rng2 As Range, C As Range Dim i As Integer Set Rng1 = Intersect(Columns("A"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstants )) Set Rng2 = Intersect(Columns("C"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstants )) For Each C In Rng1 i = i + 1 Cells(i, 4) = C Next i = 0 For Each C In Rng2 i = i + 1 Cells(i, 6) = C Next Columns("A:C").Delete End Sub Regards, Greg -----Original Message----- Try one of the following two options. 'Preserve spacing in Column A option Sub Test() Dim Rng1 As Range, Rng2 As Range Dim C As Range, TempAr() As String Dim i As Integer Set Rng1 = Intersect(Columns("A"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) Set Rng2 = Intersect(Columns("C"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) For Each C In Rng2 i = i + 1 ReDim Preserve TempAr(i) TempAr(i) = C.Value Next i = 0 For Each C In Rng1 i = i + 1 C.Offset(, 3) = C C.Offset(, 5) = TempAr(i) Next Columns("A:C").Delete End Sub 'Remove blanks in Columns A and C option Sub Test2() Dim Rng1 As Range, Rng2 As Range, C As Range Dim i As Integer Set Rng1 = Intersect(Columns("A"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) Set Rng2 = Intersect(Columns("C"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) For Each C In Rng1 i = i + 1 Cells(i, 4) = C Next Regards, Greg . |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The lines where I specify the ranges for Rng1 and Rng2 are
better written as follows. I forgot that you can specify a subset of the active sheet using SpecialCells. Correct for word wrap. Set Rng1 = ActiveSheet.Columns("A").SpecialCells (xlConstants) Set Rng2 = ActiveSheet.Columns("C").SpecialCells (xlConstants) Regards, Greg -----Original Message----- I did a sloppy copy and paste. Macro Test2 should be: Sub Test2() Dim Rng1 As Range, Rng2 As Range, C As Range Dim i As Integer Set Rng1 = Intersect(Columns("A"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) Set Rng2 = Intersect(Columns("C"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) For Each C In Rng1 i = i + 1 Cells(i, 4) = C Next i = 0 For Each C In Rng2 i = i + 1 Cells(i, 6) = C Next Columns("A:C").Delete End Sub Regards, Greg -----Original Message----- Try one of the following two options. 'Preserve spacing in Column A option Sub Test() Dim Rng1 As Range, Rng2 As Range Dim C As Range, TempAr() As String Dim i As Integer Set Rng1 = Intersect(Columns("A"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) Set Rng2 = Intersect(Columns("C"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) For Each C In Rng2 i = i + 1 ReDim Preserve TempAr(i) TempAr(i) = C.Value Next i = 0 For Each C In Rng1 i = i + 1 C.Offset(, 3) = C C.Offset(, 5) = TempAr(i) Next Columns("A:C").Delete End Sub 'Remove blanks in Columns A and C option Sub Test2() Dim Rng1 As Range, Rng2 As Range, C As Range Dim i As Integer Set Rng1 = Intersect(Columns("A"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) Set Rng2 = Intersect(Columns("C"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) For Each C In Rng1 i = i + 1 Cells(i, 4) = C Next Regards, Greg . . |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Greg Wilson" wrote in message ...
The lines where I specify the ranges for Rng1 and Rng2 are better written as follows. I forgot that you can specify a subset of the active sheet using SpecialCells. Correct for word wrap. Set Rng1 = ActiveSheet.Columns("A").SpecialCells (xlConstants) Set Rng2 = ActiveSheet.Columns("C").SpecialCells (xlConstants) Regards, Greg -----Original Message----- I did a sloppy copy and paste. Macro Test2 should be: Sub Test2() Dim Rng1 As Range, Rng2 As Range, C As Range Dim i As Integer Set Rng1 = Intersect(Columns("A"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) Set Rng2 = Intersect(Columns("C"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstant s)) For Each C In Rng1 i = i + 1 Cells(i, 4) = C Next i = 0 For Each C In Rng2 i = i + 1 Cells(i, 6) = C Next Columns("A:C").Delete End Sub Regards, Greg -----Original Message----- Try one of the following two options. 'Preserve spacing in Column A option Sub Test() Dim Rng1 As Range, Rng2 As Range Dim C As Range, TempAr() As String Dim i As Integer Set Rng1 = Intersect(Columns("A"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) Set Rng2 = Intersect(Columns("C"), _ ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) For Each C In Rng2 i = i + 1 ReDim Preserve TempAr(i) TempAr(i) = C.Value Next i = 0 For Each C In Rng1 i = i + 1 C.Offset(, 3) = C C.Offset(, 5) = TempAr(i) Next Columns("A:C").Delete End Sub 'Remove blanks in Columns A and C option Sub Test2() Dim Rng1 As Range, Rng2 As Range, C As Range Dim i As Integer Set Rng1 = Intersect(Columns("A"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) Set Rng2 = Intersect(Columns("C"), ActiveSheet.Cells.SpecialCells(xlCellTypeConstan ts)) For Each C In Rng1 i = i + 1 Cells(i, 4) = C Next Regards, Greg . . I want to say thank you to all that posted solutions . You have been very helpful . Sincerely Mason |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Very basic VBA question. | Excel Discussion (Misc queries) | |||
basic question | New Users to Excel | |||
Basic question...sorry | Excel Worksheet Functions | |||
Simple for you, tough for me, basic excel question | Excel Discussion (Misc queries) | |||
Basic Question of Excel | Excel Programming |