screenshot - cell values have been changed for simplicity I am new to VBA and need to build a data processing pipeline for mass spectrometry data. The instrument generates an output data file always in the same format: 9 columns (A-I), column B has 35 rows for every sample (that is because the instrument quantifies 35 analytes in every sample and reports each analysis as an individual result, every analysis report corresponds to a row; all rows with the same sample name -35- correspond to the same sample). Column H is the most important one; this column contains the quantified values for each of the 35 analytes. Here, 35 rows (for 35 analytes) correspond to the same sample (have the same sample name in column B).
There are a couple of things I need and I cannot figure out what would be the best strategy:
Starting with cell B2 in the original instrument report (for all intents and purposes, this would be an Excel spreadsheet), in an Excel file with multiple sheets, to build the list of sample names I need to:
- copy the report cell value (B2) only (no formats, e.g.), and paste it in a second spreadsheet (at A3).
- Offset 35 cells down in the original report; offset one cell down in the destination sheet
- copy the report cell value (B36) only, and paste it in the spreadsheet from #1 above (at A4)
I need to repeat this (B72 in report to A5 in destination, B107 in report to A6 in destination, etc.) until the report cell is empty. This stops the first task.
The second task is to move to column H in the instrument report spreadsheet, pick the first 35 numerical values (always starting at H2) and transpose them to a row in a second spreadsheet (same as #1 above) that matches the sample names. That is,
1.1. copy range H2:H37 in the report spreadsheet 1.2. paste.special (transpose) to the row starting in cell B3 in a second spreadsheet (same as #1 above) 1.3. offset to range H38:H73 in report; offset one cell down in destination sheet 1.4. copy range H:38-H:73, paste.special (transpose) to row starting at B4 in a second spreadsheet (same as #1 above)
And so forth until I enter all the data in the report file.
This is what I got so far:
Sub transpose()
Sheets("RAW").Select
Range("D2:D36").Select
Selection.Copy
Sheets("transpose").Select
Range("C2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, transpose:=True
Sheets("RAW").Activate
Range("B2").Select
Do Until IsEmpty(ActiveCell)
Worksheets("transpose").Range("B3") = Worksheets("RAW").Range("B2").Value
ActiveCell.Offset(1, 0).Select
Loop
End Sub
my other macros
Sheets("raw").Select
Range("D2:D36").Select
Selection.Copy
Sheets("transposed").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, transpose:=True
Sheets("raw").Select
Range("B2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("transposed").Select
Range("A4").Select
ActiveSheet.Paste
Sheets("raw").Select
Range("H2:H36").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("transposed").Select
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, transpose:=True
...
It seems like I want to combine both of these into one. I am having trouble with that, maybe my strategy is not the best.
Any help/comments would be greatly appreciated!