PDF import, rows?

afc171

Board Regular
Joined
Jan 14, 2017
Messages
152
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I am importing a PDF file which imports exactly the way it is in the PDF file in to Excel, but how do I get it all to be on 1 row?

Amount.png


I need everything in column C so it looks as below, no spaces but with a comma after each MG (or sometimes UG)?

2x0.25mg,2x1mg,1x6mg
6x1mg
13x0.5mg,2x1.15mg

Thank you
 
It is line breaks, I replaced the Column with CTRL+J and comma so that is sorted now.
 
Upvote 0
Maybe?
VBA Code:
Option Explicit

Sub FormatColumnC()
    Dim cell        As Range

    Dim rng         As Range
    Set rng = ThisWorkbook.Worksheets("Sheet1") _
            .Range("C2:C" & ThisWorkbook.Worksheets("Sheet1") _
            .Cells(ThisWorkbook.Worksheets("Sheet1") _
            .Rows.Count, "C").End(xlUp).Row)    ' Replace Sheet1 with your sheet name
    Application.ScreenUpdating = False

    With CreateObject("VBScript.RegExp")
        .Global = True
        .IgnoreCase = True
        .Pattern = "(mg|ug)(\d)"

        For Each cell In rng

            If Not IsEmpty(cell.Value) Then
                cell.Value = .Replace(cell.Value, "$1,$2")
            End If

        Next cell

    End With

    Set rng = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks Mike,

I think that just shows them instead of hidden...

2.png
 
Upvote 0
VBA Code:
            If Not IsEmpty(cell.Value) Then
                cell.Value = Replace(cell.Value, vbLf, "")
                cell.Value = .Replace(cell.Value, "$1,$2")
            End If
 
Upvote 0
It is line breaks, I replaced the Column with CTRL+J and comma so that is sorted now.
line breaks?
Code:
Sub FormatAmount()
Dim lastRow As Long, cell_ As Range, rng As Range
    With ThisWorkbook.Worksheets("Sheet1")
        lastRow = .Range("C" & Rows.Count).End(xlUp).Row
        If lastRow = 1 Then Exit Sub    ' no data
        Set rng = .Range("C2:C" & lastRow)
    End With
    Application.ScreenUpdating = False
    For Each cell_ In rng
        cell_.Value = Replace(cell_.Value, vbLf, ",")
    Next cell_
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

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