copy text onto seperate lines

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have this code..

Code:
Sub COPY_Text()
    With Sheets("sheet1")
    For MY_ROWS = 1 To 54
        If .Range("C" & MY_ROWS).Font.Underline = xlUnderlineStyleSingle Then
            MY_TEXT = MY_TEXT & .Range("C" & MY_ROWS).Value & ", "
        End If
    Next MY_ROWS
    If MY_TEXT <> "" Then
        Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(0, 6).Value = Left(MY_TEXT, Len(MY_TEXT) - 2)
      
        MY_TEXT = ""
    End If
    
    End With
    
End Sub

It will look down column C and copy any text strings that are underlined and paste them into a separate sheet..

Example: if sheet1 column c holds following..

A
Simple
Test
Hope
It
Works

the code above will give result of:

A,Test

However, I would like it to be displayed in sheet2 like below..

A
Test

so separate line and without the , to separate

any help appreciated
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi
How about
Code:
Sub COPY_Text()
'redspanna

    Dim MY_ROWS As Long

    With Sheets("Sheet1")
        For MY_ROWS = 1 To 54
            If .Range("C" & MY_ROWS).Font.Underline = xlUnderlineStyleSingle Then
                Sheets("Sheet2").Range("G" & Rows.Count).End(xlUp).Offset(1).Value = .Range("C" & MY_ROWS).Value
            End If
        Next MY_ROWS
    End With
    
End Sub
 
Upvote 0
Glad to help

a follow up question if I may relating to where the copy/paste is taken / put?

I have adjusted the first part of the code to select a certain worksheet from another workbook (called Counters Report) determined from a cell ref ..
this is the actual sheet name which I want the underlined text copied from

I then want to go back to another open workbook called 'Master Report' , select the 'Report' sheet and then paste the copied text into.

How can this be achieved using the part correct code below?

Code:
Sub Copy_Text()
'redspanna

Application.ScreenUpdating = False
Dim MY_ROWS As Long
Dim REPORT_DATA As Worksheet
Dim LAST_ROW As Long
Sheets("front").Select
Range("M15").Select
Selection.Copy

For Each WB In Workbooks
If WB.Name Like "Counters Report*" Then
WB.Activate
Sheets("Front").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Worksheets(Worksheets("Front").Range("A1").Text).Activate


        For MY_ROWS = 41 To 154
           If .Range("C" & MY_ROWS).Font.Underline = xlUnderlineStyleSingle Then
              Sheets("Sheet2").Range("G" & Rows.Count).End(xlUp).Offset(1).Value = .Range("C" & MY_ROWS).Value
         End If
   Next MY_ROWS
    End With


End If
Next

appreciate any help again
 
Upvote 0
Untested but try
Code:
Sub Copy_Text()
'redspanna

    Application.ScreenUpdating = False
    Dim MY_ROWS As Long
    Dim REPORT_DATA As Worksheet
    Dim LAST_ROW As Long
    Dim wb As Workbook
    Dim DestWs As Worksheet
    
    
'    Sheets("front").Select
'    Range("M15").Select
'    Selection.Copy
    Set DestWs = Workbooks("Master Report.[COLOR=#ff0000]xlsm[/COLOR]").Worksheets("Report")
    For Each wb In Workbooks
        If wb.Name Like "Counters Report*" Then
            wb.Activate
            Sheets("Front").Select
            Range("A1").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            With Worksheets(Worksheets("Front").Range("A1").Text).Activate
                For MY_ROWS = 41 To 154
                       If .Range("C" & MY_ROWS).Font.Underline = xlUnderlineStyleSingle Then
                          DestWs.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = .Range("C" & MY_ROWS).Value
                     End If
                Next MY_ROWS
            End With
        End If
    Next
    
End Sub
You may need to change the file extension in red
 
Upvote 0
Thanks again Fluff

I'm getting an Object Required error and the code is stoping on this line..
Code:
 If .Range("C" & MY_ROWS).Font.Underline = xlUnderlineStyleSingle Then

any thoughts??

There are defo lines of text that are underlined in column c so not sure why the error
 
Upvote 0
Thanks again Fluff

I'm getting an Object Required error and the code is stoping on this line..
Code:
 If .Range("C" & MY_ROWS).Font.Underline = xlUnderlineStyleSingle Then

any thoughts??

There are defo lines of text that are underlined in column c so not sure why the error
 
Upvote 0
:oops: this line
Code:
With Worksheets(Worksheets("Front").Range("A1").Text).Activate
Should be
Code:
With Worksheets(Worksheets("Front").Range("A1").Text)
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,737
Members
449,185
Latest member
hopkinsr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top