Select repeating range?

SHRIMPLab

New Member
Joined
Mar 3, 2011
Messages
3
Greetings.

This is likely a simple problem but I haven't found a solution yet (at least not one I understand) so I hope to harness the considerable power of your collective knowledge.

I have a worksheet with data arranged in one column (B). Each block of data (of which there can be a varying number) is 148 lines long and separated by the word 'Finished' plus a blank line. The ultimate goal is to select each block of data and transpose it as a new row in another workbook.

My problem is how to select each block of data without directly naming it? B1:B148, B151:B298,.... just won't do.

I hope I was clear enough. Obviously I have very little VBA experience so I'd appreciate any help you could offer. Thanks in advance.

-- Windows XP, Excel 2003. --
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
SHRIMPLab,

Welcome to the MrExcel forum.


Because of the size of your data sets, this may be the best way to get help.

To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

You can upload your workbook to www.box.net and provide us with a link to your workbook.
 
Upvote 0
Thanks for the replies and the welcome.

texaslynn, I had a look at the similar post and while I understand the concept (to find a start and end point and select everything in between) I'm not sure how to modify it for my situation. Basically I'd like to translate this into VBA-ese:

"Select 148 lines in column B, skip two lines, select the next 148 lines, skip two, and so on until you reach the end. Pretty please."

Here's a link to a sample data file for those that are interested: http://www.box.net/shared/cjx9pmilo3

The 'Data' sheet is what is spit out at me and the 'Result' sheet is the beginning of what I'd like to achieve.

Thanks again.
 
Upvote 0
SHRIMPLab,

Thanks for the workbook.


Sample data before the macro:


Excel Workbook
AB
1SHRIMP Analytical Conditions forMonday Feb 28 2011 10:23:28
2
3IP588
4Session11-032
5Kohler100b
6Spot6266-8.1
7Source Slit (m)80
8Alpha Y inner (mm)24
9Alpha Z outer (mm)22.75
10Alpha Z (mm)24
11Energy Slit inner (mm)0
12Energy Slit outer (mm)24.5
13Collector Slit (m)90
14PBM range10nA
15PBM value (nA)-5.3
16SBM range =300pA
17SBM value (pA)67.1
18Primary Energy
19bits43597
20V10000.3
21Source Steering Y Deflection
22bits-2833
23V20.6
24Source Steering Z Deflection
25bits-854
26V5
27Matching Lens
28bits16484
29V3777.4
30Matching Lens Steering Y Deflection
31bits-2738
32V20
33Matching Lens Steering Z Deflection
34bits1413
35V12.6
36Transfer Lens
37bits15453
38V3539.3
39Wien Magnet
40bits-8566
Data





After the macro (not all 148 columns shown for brevity):


Excel Workbook
ABCDEFG
1SHRIMP Analytical Conditions forIPSessionKohlerSpotSource Slit (m)
2Monday Feb 28 2011 10:23:2858811-032100b6266-8.180
3Monday Feb 28 2011 10:46:1358811-032100b6266-8.280
4Monday Feb 28 2011 11:00:5758811-032100b1242-1.180
5Monday Feb 28 2011 11:23:4358811-032100b6266-13.180
6Monday Feb 28 2011 11:39:5958811-032100b1242-2.180
7Monday Feb 28 2011 11:57:2358811-032100b1242-3.180
8Monday Feb 28 2011 12:16:1858811-032100b6266-10.180
9Monday Feb 28 2011 12:31:0058811-032100b10356-2.180
10Monday Feb 28 2011 12:57:4058811-032100b10356-11.180
11Monday Feb 28 2011 13:10:1658811-032100b10356-5.180
12Monday Feb 28 2011 13:22:5358811-032100b10356-6.180
13Monday Feb 28 2011 13:36:0258811-032100b10356-11.180
14Monday Feb 28 2011 13:54:3758811-032100b10356-10.180
15Monday Feb 28 2011 14:09:2458811-032100b6266-12.180
16Monday Feb 28 2011 14:24:3958811-032100b10356-1280
17Monday Feb 28 2011 14:42:2358811-032100b10356-16.180
18Monday Feb 28 2011 14:56:2958811-032100b10356-22.180
19Monday Feb 28 2011 17:23:2958811-032100b6266-11.180
20Monday Feb 28 2011 17:36:0958811-032100b1242-4.180
21Monday Feb 28 2011 17:48:4958811-032100b10356-13.180
22Monday Feb 28 2011 18:01:2758811-032100b10356-15.180
23Monday Feb 28 2011 18:14:0658811-032100b10356-17.180
24Monday Feb 28 2011 18:26:4258811-032100b10356-21.180
25Monday Feb 28 2011 18:39:1958811-032100b10356-25.180
26Monday Feb 28 2011 18:51:5758811-032100b10356-27.180
27Monday Feb 28 2011 19:04:3458811-032100b10356-28.180
28Monday Feb 28 2011 19:17:1358811-032100b6266-11.280
29Monday Feb 28 2011 19:29:5358811-032100b1242-5.180
30Monday Feb 28 2011 19:42:3458811-032100b10356-29.180
31Monday Feb 28 2011 19:55:1158811-032100b10356-31.180
32Monday Feb 28 2011 20:07:4858811-032100b10356-32.180
33Monday Feb 28 2011 20:20:2458811-032100b10356-33.180
34Monday Feb 28 2011 20:33:0058811-032100b10356-37.180
35Monday Feb 28 2011 20:45:3758811-032100b10356-38.180
36Monday Feb 28 2011 20:58:1558811-032100b10356-40.180
37Monday Feb 28 2011 21:10:5458811-032100b6266-12.280
38Monday Feb 28 2011 21:23:3358811-032100b1242-6.180
39
Results





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub SHRIMPLab()
' hiker95, 03/03/2011
' http://www.mrexcel.com/forum/showthread.php?t=533361
Dim w1 As Worksheet, wR As Worksheet
Dim c As Range, firstaddress As String
Dim NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Data")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
wR.Range("A1").Resize(, 148).Value = Application.Transpose(w1.Range("A1:A148").Value)
NR = 1
With w1.Columns(1)
  Set c = .Find("IP", LookIn:=xlValues, LookAt:=xlWhole)
  If Not c Is Nothing Then
    firstaddress = c.Address
    Do
      NR = NR + 1
      wR.Range("A" & NR).Resize(, 148).Value = Application.Transpose(w1.Range("B" & c.Row - 2 & ":B" & c.Row + 146))
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstaddress
  End If
End With
Application.ScreenUpdating = True
End Sub


Then run the SHRIMPLab macro.
 
Upvote 0
Excellent, hiker95. Excellent. It works perfectly.

Many thank yous for taking the time to write the entire macro for me.

Now to show it off and take all the credit... ;)
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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