Importing CSV into a data block vs. a table.

Stevo81

New Member
Joined
Jun 30, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello!

Here is my challenge: I would like to be able to import a csv file into a block of cells vs. just importing into a table. I am working on a report that would import the data into a formatted section that would repeat as many time as there are rows of data in the csv. I have attached a picture. The grayed out section does not need anything imported into it since that is a place for handwritten notes once it is printed.

Essentially, I would like to populate the fields from the CSV and then repeat the block for the next patient, and so on. Thank you for your help!!

Steve
 

Attachments

  • RoundingReport.JPG
    RoundingReport.JPG
    81.8 KB · Views: 16

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi Stevo81, welcome to the MrExcel Board.

I think we would have to see what your source data CSV looks like in order to know how to parse it out to your desired data block. Additionally, if the source data contains more than one patient where on your sheet does the next patient data block reside.
 
Upvote 0
Hello igold!

Thank you for your response. I have attached a few more screenshots.
 

Attachments

  • CSV Source.JPG
    CSV Source.JPG
    140.9 KB · Views: 14
  • RoundingReport2.JPG
    RoundingReport2.JPG
    104.2 KB · Views: 14
Upvote 0
That's a start. The only field I don't think I see is "Surgeon".
 
Upvote 0
Sorry about that. Actually the "Surgeon" field is manually selected from a drop down list, it is not sourced from the CSV.
 
Upvote 0
Try this. This code has both the source (CSV) and the Report in the same workbook. If that is not the case, then I will need more information (Workbook names of each). Additionally, I have named your sheets as "CSV Source" and "RoudingReport". Please change code where indicated to what the correct sheet names are.

VBA Code:
Sub CsvImport()

    Dim arr
    Dim i As Long, ct As Long, lRow As Long
    Dim wsC As Worksheet, wsR As Worksheet
    
    Application.ScreenUpdating = False
    Set wsC = Worksheets("CSV Source")              'Rename Here
    Set wsR = Worksheets("RoundingReport")          'Rename Here
    
    lRow = wsC.Cells(Rows.Count, 11).End(xlUp).Row
    arr = wsC.Range("A2:M" & lRow)
    For i = 1 To UBound(arr)
        wsR.Cells(5 + ct, 4) = arr(i, 3)    'Physician
        wsR.Cells(4 + ct, 8) = arr(i, 4)    'DOB
        wsR.Cells(4 + ct, 6) = arr(i, 5)    'Sex
        wsR.Cells(5 + ct, 8) = arr(i, 6)    'Admit Date
        wsR.Cells(5 + ct, 7) = arr(i, 7)    'Stay Days
        wsR.Cells(3 + ct, 8) = arr(i, 9)    'Visit ID
        wsR.Cells(4 + ct, 4) = arr(i, 11)  'Patient Name
        wsR.Cells(6 + ct, 4) = arr(i, 13)  'Diagnosis
        ct = ct + 5
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
igold,

Thank you so much for your help! I've been tweaking things a little to suit my form but the code has worked perfectly. I really appreciate your time.

Thank you!
Steve
 
Upvote 0
You're welcome, I was happy to help. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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