Extracting specific data from one spread sheet, but editing the data at the same time, then repeating the process to a third one

PA_VA13

New Member
Joined
Jul 2, 2020
Messages
31
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone! I just started learning VBA excel coding. VBA excel for dummies and tutorials have helped a lot but I am still stumped on how to create a macro to do everything in one go. Right now, it takes me about 1+ hours to manually transfer data even with the few formulas and codes that I have been able to create to assist. I need to make it auto populate as much as possible to not only reduce the amount of time involved but also so that my co-worker who covers me when I am away can do it, as she is not as tech savvy.



We get data from one of our instruments that we manually transfer into a spread sheet (“Case Load Report”; Fig.1). I need to pull specific data for my techs (highlighted in green in Fig. 2) and paste into another spread sheet (“HZ report”; Fig.3). After the data is double checked (sometimes there is no case pathologist provided) I then take specific data from that spread sheet (highlighted in blue Fig.4) and paste it into a third spread sheet for my pathologists (“Path Case Distribution”; Fig.5)



The 1st transfer process gets even more complex as I also need to auto edit the ID# data when it is transferred to the tech sheet (“HZ report”; Fig.3). Each case ID (Ex: SP-20-12345) has one or more parts to it represented after the “.” (Ex: part one = SP-20-12345.1; part two = SP-20-12345.2, etc.) with samples of each part represented by letters (Ex: SP-20-12345.1A; SP-20-33456.11.BC). I need to extract just the alpha characters after the “.” for each ID # (Ex: changing SP-20-3945.1A to SP-20-3945.1; SP-20-4008.1AB to Sp-20-4008.1) and then get a count of each duplicate in order to get a total block count for each part of the ID# to reduce the amount of paperwork as the original way is too much (Example of completed sheet Fig.6).



I have only been able to figure out how to remove everything after the “.” with the below formula.



=IF(LEFT('Case Load Report'!A8,10)="","",CONCAT(LEFT('Case Load Report'!A8,IFERROR(FIND(".",'Case Load Report'!A8,1)-1,""))))



I have tried the Pivot Table but I could not get that information to work with my next transfer process.



Once everything has been double checked in the “HZ Report” spread sheet, then it gets even more confusing. I wanted to create a button that would start the next transfer process. It needs to auto edit the ID# data again to only the case ID# (EX: from SP-20-3945.1 to SP-20-3945) and also give me an overall total block count for that case by counting the duplicates, but then also do a search to locate the column for a specific pathologist and then paste the edited information in their section (Ex: Fig.7).



Besides removing all of the cassette information I have no clue on how to go about doing this part, or if it is even possible with VBA.



I defiantly picked a big project to start off with as a beginner so any suggestions would be great or if you know of any tutorials that would help I would greatly appreciate it!
 

Attachments

  • FIG.1.png
    FIG.1.png
    85.2 KB · Views: 20
  • FIG.2.png
    FIG.2.png
    107.1 KB · Views: 19
  • FIG.3.png
    FIG.3.png
    24.8 KB · Views: 16
  • FIG.4.png
    FIG.4.png
    21.6 KB · Views: 18
  • FIG.5.png
    FIG.5.png
    24.7 KB · Views: 16
  • FIG.6.png
    FIG.6.png
    11.3 KB · Views: 14
  • FIG.7.png
    FIG.7.png
    19.3 KB · Views: 18

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Welcome to the forum :)

Your string conundrum
With A8 value SP-20-3945.1A
Is the string consistently 13 characters
Is the pattern consistently ZZ-99-9999.9Z ( Z = any alpha character , 9 = any numeric character) ?

=LEFT(A8,12) returns SP-20-3945.1
=LEFT(A8,10) returns SP-20-3945

Data
You have provided lots of pictures but no data.
Recreating it would be time consuming and error prone for anyone trying to help you.
XL2BB is a tool which allows you to post your sample data to the forum
Make sure that the data is typical of the real data
 
Upvote 0
Thank you for letting me know about the XL2BB. Hopefully I post the sample data right. The 1st post is the "Case Load Report" data, the second is the "HZ report" data, and the 3rd is the "Path Case Distribution" data.

Path Case Assignment_1.0_Macro Enabled.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXY
7IDExternal ReferenceCase TypeProcedureTissue TypeSiteCase PathologistDate Added
8SP-20-3945.1ASurgical PathologyTISSCOLONSIGMOID COLONSS6/24/2020 8:11
9SP-20-3946.1ASurgical PathologyTISSCOLON1. ILEOCECAL VALVEVA6/24/2020 8:11
10SP-20-3946.2ASurgical PathologyTISSCOLON2. CECUMVA6/24/2020 8:11
11SP-20-3946.3ASurgical PathologyTISSCOLON3. TRANSVERSE COLONVA6/24/2020 8:11
12SP-20-3946.4ASurgical PathologyTISSCOLON4. DESCENDING COLONVA6/24/2020 8:11
13SP-20-3947.1ASurgical PathologyTISSSTOMACHSTOMACHYM6/24/2020 8:12
14SP-20-3948.1ASurgical PathologyTISSCOLON1. CECUMCL6/24/2020 8:12
15SP-20-3948.2ASurgical PathologyTISSCOLON2. ASCENDING COLONCL6/24/2020 8:12
16SP-20-3949.1ASurgical PathologyTISSCOLON1. ASCENDING COLONPC6/24/2020 8:12
17SP-20-3949.2ASurgical PathologyTISSCOLON2. TRANSVERSE COLONPC6/24/2020 8:12
18SP-20-3949.3ASurgical PathologyTISSCOLON3. SIGMOID COLONPC6/24/2020 8:12
19SP-20-3950.1ASurgical PathologyTISSCOLON1. TRANSVERSE COLONSH6/24/2020 8:13
20SP-20-3950.2ASurgical PathologyTISSCOLON2. DESCENDING COLONSH6/24/2020 8:13
21SP-20-3950.3ASurgical PathologyTISSCOLON3. RECTUMSH6/24/2020 8:13
22SP-20-3951.1ASurgical PathologyTISSCOLON1. DESCENDING COLONSS6/24/2020 8:13
23SP-20-3951.2ASurgical PathologyTISSCOLON2. SIGMOID COLONSS6/24/2020 8:13
24SP-20-3952.1ASurgical PathologyGOBONERIGHT DISTAL ULNA BONEVA6/24/2020 8:14
25SP-20-3953.1ASurgical PathologyTISSSKINRIGHT POSTAURICULAR SKINYM6/24/2020 8:17
26SP-20-3954.10ASurgical PathologyPBPROSTATE10. PROSTATE BIOPSY, LEFT MEDIAL MIDPC6/24/2020 8:24
27SP-20-3954.11ASurgical PathologyPBPROSTATE11. PROSTATE BIOPSY, LEFT LATERAL BASEPC6/24/2020 8:24
28SP-20-3954.12ASurgical PathologyPBPROSTATE12. PROSTATE BIOPSY, LEFT MEDIAL BASEPC6/24/2020 8:24
29SP-20-3954.13ASurgical PathologyPBPROSTATE13. PROSTATE BIOPSY, RIGHT MIDGLAND ANTERIOR LATPC6/24/2020 8:24
30SP-20-3954.14ASurgical PathologyPBPROSTATE14. PROSTATE BIOPSY, RIGHT MIDGLAND ANTERIOR LATPC6/24/2020 8:24
31SP-20-3954.15ASurgical PathologyPBPROSTATE15. PROSTATE BIOPSY, RIGHT MIDGLAND ANTERIOR LATPC6/24/2020 8:24
32SP-20-3954.16ASurgical PathologyPBPROSTATE16. PROSTATE BIOPSY, RIGHT MIDGLAND ANTERIOR LATPC6/24/2020 8:24
33SP-20-3954.1ASurgical PathologyPBPROSTATE1. PROSTATE BIOPSY, RIGHT LATERAL APEXPC6/24/2020 8:24
34SP-20-3954.2ASurgical PathologyPBPROSTATE2. PROSTATE BIOPSY, RIGHT MEDIAL APEXPC6/24/2020 8:24
Cerebro Case Load Report


Path Case Assignment_1.0_Macro Enabled.xlsm
ABCDEFGHIJKLMNOPQRST
1Date/Time24 Jun 2020Total # Per Pathologist
2Total Surgical Blocks (SP)PathologistBlocksPointsPathologistBlocksPoints
3Total Cytology SurPath Slides (CY)SH0CL0
4Total Cytology Cell Blocks (CYBLK)SS0PC0
5Total Blocks for the DayVA0SC0
6YM00
7
8
9ID (Accession #)# BLOCKSProcedureTissue TypeCase PathologistMicrotomistCorrelating CasesComments
10
11
12
13
14
15
16
17
Cerebro HZ Report_vr1
Cell Formulas
RangeFormula
K3K3=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
K4K4=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
K5K5=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
K6K6=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
O3O3=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
O4O4=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
O5O5=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
O6O6=COUNTIF('Cerebro Case Load Report'!S8:S3000,"...")
Named Ranges
NameRefers ToCells
Pathologist='Cerebro Case Load Report'!$S$8:$U$1552K3:K6


Path Case Assignment_1.0_Macro Enabled.xlsm
ABCDEFGHIJKLMNOPQR
1Total Surgical Blocks (SP)Total # Per Pathologist
2Total Cytology SurPath Slides (CY)PathologistBlocksPointsPathologistBlocksPoints
3Total Cytology Cell Blocks (CYBLK)SH0CL0
4Total Blocks for the DaySS0PC0
5VA0SC0
6YM00
7
8Pathologist Case Distribution
9SHSSVAYMCLPC
10Case ##BLKTISSCase ##BLKTISSCase ##BLKTISSCase ##BLKTISSCase ##BLKTISSCase ##BLKTISS
11SP-20-39451TISSSP-20-39464TISS
12SP-20-39471TISS
13
14
15
16
17
18
19
20
21
22
23
Path Case Distribution
Cell Formulas
RangeFormula
J3J3=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
J4J4=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
J5J5=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
J6J6=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
N3N3=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
N4N4=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
N5N5=COUNTIF('Cerebro Case Load Report'!S8:S3000,"SC")
N6N6=COUNTIF('Cerebro Case Load Report'!S8:S3000,"...")
Named Ranges
NameRefers ToCells
Pathologist='Cerebro Case Load Report'!$S$8:$U$1552J3:J6
Cells with Data Validation
CellAllowCriteria
L11:L13List=$EE$12:$EE$21
I13:I23List=$EE$12:$EE$21
C14:C23List=$EE$12:$EE$39
 
Upvote 0
This is the Pivot table a friend of mine helped me make to remove just the Alpha characters after the "." but we couldn't get it to work with auto transferring to the "HZ report" correctly with the rest of the row data. What I think makes it so difficult for me is that the # of characters before the "." and after the "." are not always the same #.

Copy of Path Case Assignment_Test.xlsm
ABCDEFGHIJKLMN
1IDRow LabelsCount of IDID
2SP-20-3945880SP-20-3945SP-20-3945.1A2039451
3SP-20-3946 - TISS - VA(blank)SP-20-3946SP-20-3946.1ASP--.A
4SP-20-3946 - TISS - VASP-20-3945 - TISS - SS1SP-20-3946SP-20-3946.2A
5SP-20-3946 - TISS - VASP-20-3946 - TISS - VA4SP-20-3946SP-20-3946.3A
6SP-20-3946 - TISS - VASP-20-3947 - TISS - YM1SP-20-3946SP-20-3946.4A
7SP-20-3947 - TISS - YMSP-20-3948 - TISS - CL2SP-20-3947SP-20-3947.1A
8SP-20-3948 - TISS - CLSP-20-3949 - TISS - PC6SP-20-3948SP-20-3948.1A
9SP-20-3948 - TISS - CLSP-20-3950 - TISS - SH3SP-20-3948SP-20-3948.2A
10SP-20-3949 - TISS - PCSP-20-3951 - TISS - SS2SP-20-3949SP-20-3949.1A
11SP-20-3949 - TISS - PCSP-20-3952 - TISS - VA1SP-20-3949SP-20-3949.2A
12SP-20-3949 - TISS - PCSP-20-3953 - TISS - YM1SP-20-3949SP-20-3949.3A
13SP-20-3950 - TISS - SHSP-20-3954 - TISS - PC16SP-20-3950SP-20-3950.1A
14SP-20-3950 - TISS - SHSP-20-3955 - TISS - CL1SP-20-3950SP-20-3950.2A
15SP-20-3950 - TISS - SHSP-20-3956 - TISS - SS16SP-20-3950
16SP-20-3951 - TISS - SSSP-20-3957 - TISS - VA3SP-20-3951
17SP-20-3951 - TISS - SSSP-20-3958 - TISS - YM1SP-20-3951
18SP-20-3952 - TISS - VASP-20-3959 - TISS - VA7SP-20-3952
19SP-20-3953 - TISS - YMSP-20-3960 - TISS - SH2SP-20-3953
20SP-20-3954 - TISS - PCSP-20-3961 - TISS - CL3SP-20-3954
21SP-20-3954 - TISS - PCSP-20-3962 - TISS - VA2SP-20-3954
22SP-20-3954 - TISS - PCSP-20-3963 - TISS - YM3SP-20-3954
23SP-20-3954 - TISS - PCSP-20-3964 - TISS - CL2SP-20-3954
24SP-20-3954 - TISS - PCSP-20-3966 - TISS - CL1SP-20-3954
25SP-20-3954 - TISS - PCSP-20-3967 - TISS - SH2SP-20-3954
26SP-20-3954 - TISS - PCSP-20-3968 - TISS - CL1SP-20-3954
27SP-20-3954 - TISS - PCSP-20-3969 - TISS - VA1SP-20-3954
28SP-20-3954 - TISS - PCSP-20-3971 - TISS - CL2SP-20-3954
29SP-20-3954 - TISS - PCSP-20-3972 - TISS - CL1SP-20-3954
30SP-20-3954 - TISS - PCSP-20-3973 - TISS - SH4SP-20-3954
31SP-20-3954 - TISS - PCSP-20-3974 - TISS - SH1SP-20-3954
32SP-20-3954 - TISS - PCSP-20-3975 - TISS - YM11SP-20-3954
33SP-20-3954 - TISS - PCSP-20-3976 - TISS - VA1SP-20-3954
34SP-20-3954 - TISS - PCSP-20-3965 - TISS - SH6SP-20-3954
35SP-20-3954 - TISS - PCSP-20-3970 - TISS - YM1SP-20-3954
36SP-20-3955 - TISS - CLCY-20-944 - CY - 1SP-20-3955
37SP-20-3956 - TISS - SSCY-20-945 - CY - 2SP-20-3956
38SP-20-3956 - TISS - SSCY-20-946 - CY - 1SP-20-3956
39SP-20-3956 - TISS - SSCY-20-947 - CY - 1SP-20-3956
40SP-20-3956 - TISS - SSCY-20-948 - CY - 1SP-20-3956
41SP-20-3956 - TISS - SSCY-20-949 - CY - 1SP-20-3956
42SP-20-3956 - TISS - SSCY-20-950 - CY - 1SP-20-3956
43SP-20-3956 - TISS - SSCY-20-951 - CY - 1SP-20-3956
44SP-20-3956 - TISS - SSCY-20-951 - CYBLK - 1SP-20-3956
45SP-20-3956 - TISS - SSGrand Total999SP-20-3956
46SP-20-3956 - TISS - SSSP-20-3956
47SP-20-3956 - TISS - SSSP-20-3956
48SP-20-3956 - TISS - SSSP-20-3956
49SP-20-3956 - TISS - SSSP-20-3956
50SP-20-3956 - TISS - SSSP-20-3956
51SP-20-3956 - TISS - SSSP-20-3956
52SP-20-3956 - TISS - SSSP-20-3956
53SP-20-3949 - TISS - PCSP-20-3949
54SP-20-3949 - TISS - PCSP-20-3949
55SP-20-3949 - TISS - PCSP-20-3949
56SP-20-3957 - TISS - VASP-20-3957
57SP-20-3957 - TISS - VASP-20-3957
58SP-20-3957 - TISS - VASP-20-3957
59SP-20-3958 - TISS - YMSP-20-3958
60SP-20-3959 - TISS - VASP-20-3959
61SP-20-3959 - TISS - VASP-20-3959
62SP-20-3960 - TISS - SHSP-20-3960
63SP-20-3960 - TISS - SHSP-20-3960
64SP-20-3961 - TISS - CLSP-20-3961
65SP-20-3961 - TISS - CLSP-20-3961
66SP-20-3962 - TISS - VASP-20-3962
67SP-20-3962 - TISS - VASP-20-3962
68SP-20-3963 - TISS - YMSP-20-3963
69SP-20-3963 - TISS - YMSP-20-3963
70SP-20-3963 - TISS - YMSP-20-3963
71SP-20-3964 - TISS - CLSP-20-3964
72SP-20-3964 - TISS - CLSP-20-3964
73SP-20-3961 - TISS - CLSP-20-3961
74SP-20-3966 - TISS - CLSP-20-3966
75SP-20-3967 - TISS - SHSP-20-3967
76SP-20-3967 - TISS - SHSP-20-3967
77SP-20-3968 - TISS - CLSP-20-3968
Gather_SPs
Cell Formulas
RangeFormula
N2N2=StripChar(L2)
N3N3=TextOnly(L2)
A2A2=IF(LEFT('Cerebro Case Load Report'!A8,10)="","",CONCAT(LEFT('Cerebro Case Load Report'!A8,IFERROR(FIND(".",'Cerebro Case Load Report'!A8,1)-1,""))))
A3:A77A3=IF(LEFT('Cerebro Case Load Report'!A9,10)="","",CONCAT(LEFT('Cerebro Case Load Report'!A9,IFERROR(FIND(".",'Cerebro Case Load Report'!A9,1)-1,"")), " - ", 'Cerebro Case Load Report'!J9, " - ", 'Cerebro Case Load Report'!S9))
I2:I77I2=IF(LEFT('Cerebro Case Load Report'!A8,10)="","",CONCAT(LEFT('Cerebro Case Load Report'!A8,IFERROR(FIND(".",'Cerebro Case Load Report'!A8,1)-1,""))))
Named Ranges
NameRefers ToCells
ID='Cerebro Case Load Report'!$A$8:$B$1088A2, I2
 
Upvote 0
Hi [U]Yongle[/U]! The string conundrum is what makes it so difficult.

With A8 value SP-20-3945.1A
The string is not consistently 13 characters. We start at SP-20-01 at the beginning of the year and then the count goes up for each new case.

The pattern is pretty consistent but not the number of characters after the second "-", so you could have ZZ-99-9999.9Z ( Z = any alpha character , 9 = any numeric character) or ZZ-99-999999.99ZZ

ZZ (represents the case type: SP = surgical; CY = cytology, etc.) - 99 (represents the year: 19 = 2019; 20 = 2020, etc.) - 9999 ( represents the case number which starts at 01 at the beginning of the year) . 99 (99 represents the subpart that always starts at 1 but then can go up to 20 or more: .1 = part one for case 3945; .8 = part eight for case 3945; .15 = part 15 for case 3945) ZZ (represents the sample taken from that subpart of the case).

So you could get any combination of the following, with the areas in bold being the only characters that stay consistent.
SP-20-3945.1A
SP-20-48053.18A
SP-20-403.4AB
CY-20-335.3C
 
Upvote 0
Hi [U]Yongle[/U], that would work great except I still need to keep the numbers after the "." so that my end number looks like SP-20-3945.1; SP-20-48053.18 etc. o_O

I recently tried the =SUBSTITUTE function where I could tell excel to remove the specific characters, but then I ran into the issue of having to repeat the code over an over for each letter of the alphabet since I can't do a range. This also poses a problem when I have an "alphabet repeat" of AA through AZ since I went through the alphabet once already.

=SUBSTITUTE(SUBSTITUTE(L8, "A", ""), "B", ""), "C", ""), "D", ""), "E", ""), "F", ""), "G", ""), "H", "")
=SUBSTITUTE(SUBSTITUTE(L8, "AA", ""), "AB", ""), "AC", ""), "AD", ""), "AE", ""), "AF", ""), "AG", ""), "AH", "")

I did find a VBA code example online (below) on a help dashboard on how to find and replace multiple text strings within a text string, but I don't think I can get it to work for my needs.

What do you think? Thank you again for your help!

Function REPLACETEXTS(strInput As String, rngFind As Range, rngReplace As Range) As String

Dim strTemp As String
Dim strFind As String
Dim strReplace As String

Dim cellFind As Range

Dim lngColFind As Long
Dim lngRowFind As Long
Dim lngRowReplace As Long
Dim lngColReplace As Long

lngColFind = rngFind.Columns.Count
lngRowFind = rngFind.Rows.Count
lngColReplace = rngFind.Columns.Count
lngRowReplace = rngFind.Rows.Count

strTemp = strInput

If Not ((lngColFind = lngColReplace) And (lngRowFind = lngRowReplace)) Then
REPLACETEXTS = CVErr(xlErrNA)
Exit Function
End If

For Each cellFind In rngFind

strFind = cellFind.Value
strReplace = rngReplace(cellFind.Row - rngFind.Row + 1, cellFind.Column - rngFind.Column + 1).Value
strTemp = Replace(strTemp, strFind, strReplace)

Next cellFind

REPLACETEXTS = strTemp

End Function
 
Upvote 0
Hi [U]Fluff[/U],

I ran your formula through my excel sheet and it did work for all cases that had just an A but it didn't work for the other letters.

Sorry the MrExcel Capture Range isn't working on my PC at the moment so I just pasted the cells from my excel sheet.

Original Case NumberAfter using the formula
SP-20-3956.7ASP-20-3956.7
SP-20-3956.8ASP-20-3956.8
SP-20-3956.9ASP-20-3956.9
SP-20-3949.1BSP-20-3949.1B
SP-20-3949.2BSP-20-3949.2B
SP-20-3949.3BSP-20-3949.3B
SP-20-3957.1ASP-20-3957.1
SP-20-3957.2ASP-20-3957.2
SP-20-3957.3ASP-20-3957.3
 
Upvote 0
I should have mentioned that it will need to be confirmed with Ctrl Shift Enter, rather than just Enter.
 
Upvote 0

Forum statistics

Threads
1,224,833
Messages
6,181,242
Members
453,026
Latest member
cknader

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