Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default macro move cell with text one to right and one up!

Hello,

I looked in the forum but could not find a good answer for my problem. I
have a sheet with a few hundred lines (download from SAP). The sheet has the
following format:

A B
1 123456
321345
text
2 213453
894352
another text line
3 723467
831487
and another text line!
etc etc

I would like to have a macro that moves the cell that contains the text one
cell to the right and one cell up!

With best regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default macro move cell with text one to right and one up!

Is this what you want

Public Sub ProcessData()
Dim LastRow As Long
Dim NumBreaks As Long
Dim IdxBreak As Long
Dim LastPos As Long
Dim i As Long
Dim j As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For i = 1 To LastRow

NumBreaks = Len(.Cells(i, "A").Value) - Len(Replace(.Cells(i,
"A").Value, vbLf, ""))
IdxBreak = NumBreaks
LastPos = Len(.Cells(i, "A").Value)
For j = LastPos To 1 Step -1

If Mid$(.Cells(i, "A").Value, j, 1) = vbLf Then

.Cells(i, IdxBreak + 1).Value = Mid$(.Cells(i,
"A").Value, j + 1, LastPos - j)
LastPos = j - 1
IdxBreak = IdxBreak - 1
End If
Next j
.Cells(i, "A").Value = Left$(.Cells(i, "A").Value, LastPos)
Next i
End With

End Sub

--
__________________________________
HTH

Bob

"TooN" wrote in message
...
Hello,

I looked in the forum but could not find a good answer for my problem. I
have a sheet with a few hundred lines (download from SAP). The sheet has
the
following format:

A B
1 123456
321345
text
2 213453
894352
another text line
3 723467
831487
and another text line!
etc etc

I would like to have a macro that moves the cell that contains the text
one
cell to the right and one cell up!

With best regards



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default macro move cell with text one to right and one up!

Hello Bob,

thanks for the quick response. I added the macro into the workbook but there
were no results after running it. Maybe i have to correct myself. The cells
with the text are in column C and i want to move them to column D (one to the
right and one up). So if there is a text line in cel C10 i want to move it to
D9.

Columns:
A B(empty) C D
HE612421100 12473265
12473265
REMOVING DEVICE
HE612421100 12510365
12510365
User Manual
HE612421100 12510465
12510465
Predicted Performance Map Overall LP
HE612421100 12510665
12510665
Nozzle Allowable Loading LP
HE612421100 12510865
12510865
Compressor Data Sheets
HE612421100 12510965
12510965
etc


thanks in advance!

"Bob Phillips" wrote:

Is this what you want

Public Sub ProcessData()
Dim LastRow As Long
Dim NumBreaks As Long
Dim IdxBreak As Long
Dim LastPos As Long
Dim i As Long
Dim j As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For i = 1 To LastRow

NumBreaks = Len(.Cells(i, "A").Value) - Len(Replace(.Cells(i,
"A").Value, vbLf, ""))
IdxBreak = NumBreaks
LastPos = Len(.Cells(i, "A").Value)
For j = LastPos To 1 Step -1

If Mid$(.Cells(i, "A").Value, j, 1) = vbLf Then

.Cells(i, IdxBreak + 1).Value = Mid$(.Cells(i,
"A").Value, j + 1, LastPos - j)
LastPos = j - 1
IdxBreak = IdxBreak - 1
End If
Next j
.Cells(i, "A").Value = Left$(.Cells(i, "A").Value, LastPos)
Next i
End With

End Sub

--
__________________________________
HTH

Bob

"TooN" wrote in message
...
Hello,

I looked in the forum but could not find a good answer for my problem. I
have a sheet with a few hundred lines (download from SAP). The sheet has
the
following format:

A B
1 123456
321345
text
2 213453
894352
another text line
3 723467
831487
and another text line!
etc etc

I would like to have a macro that moves the cell that contains the text
one
cell to the right and one cell up!

With best regards




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
Move comment into cell as text PhooPhan Excel Discussion (Misc queries) 4 September 2nd 08 10:17 AM
Find text and move it to other cell broogle Excel Programming 7 September 20th 05 08:19 AM
Macro to move text from one field to another Wayne via OfficeKB.com Excel Programming 1 June 21st 05 10:14 PM
VBA Creating a Macro to Move some of the text from one cell to another Lowell B. Copeland Excel Programming 4 August 28th 03 08:15 PM
VBA Creating a Macro to Move some of the text from one cell to another Ron de Bruin Excel Programming 0 August 28th 03 07:21 PM


All times are GMT +1. The time now is 12:46 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"