Locate data and copy it to a new sheet

anilsharaf

New Member
Joined
Apr 8, 2014
Messages
43
Office Version
  1. 2007
Platform
  1. Windows
This is the data which has abstract at the end of every room sitting plan:
Sitting Principle and Module.xlsm
ABCDEFGH
1room1 (50)Sitting Table
20Colm 1Colm 2Colm 3Colm 4Colm 56
3Row 109110111109120111209130
4Row 99109111099119111199129
5Row 89108111089118111189128
6Row 79107111079117111179127
7Row 69106111069116111169126
8Row 59105111059115111159125
9Row 49104111049114111149124
10Row 39103111039113111139123
11Row 29102111029112111129122
12EntranceRow 19101111019111111119121
13Abstract
14ClassFromToTotal
159A9101913030
1611a111011112020
17Total50
18room2 (60)
190Colm 1Colm 2Colm 3Colm 4Colm 5Colm 6
20Row 1091401121091501122092019211
21Row 991391120991491121991599210
22Row 891381120891481121891589209
23Row 791371120791471121791579208
24Row 691361120691461121691569207
25Row 591351120591451121591559206
26Row 491341120491441121491549205
27Row 391331120391431121391539204
28Row 291321120291421121291529203
29EntranceRow 191311120191411121191519202
30Abstract
31ClassFromToTotal
329A9131915929
339B9201921111
3411b112011122020
35Total60
36Room3 (25)
370Colm 1Colm 2Colm 3Colm 4Colm 5
38Row 59216112259221113049226
39Row 49215112249220113039225
40Row 39214112239219113029224
41Row 29213112229218113019223
42EntranceRow 19212112219217112269222
43Abstract
44ClassFromToTotal
459B9212922615
4611b11221112266
4711c11301113044
48Total25
49room4(44)
500Colm 1Colm 2Colm 3Colm 4Colm 5Colm 6
51Row 8X9249XXX9234
52Row 7113259248113189241113119233
53Row 6113249247113179240113109232
54Row 5113239246113169239113099231
55Row 4113229245113159238113089230
56Row 3113219244113149237113079229
57Row 2113209243113139236113069228
58Row 1113199242113129235113059227
59Entrance
60Abstract
61ClassFromToTotal
629B9227924923
6311c113051132521
64Total44
TestData


I want this consolidated data in another sheet named 'consolidated'
Sitting Principle and Module.xlsm
ABCDE
1Classwise Abstract of All Rooms
2ClassfrmtototalRoomNo
311a1110111120201
411b1120111220202
511b112211122663
611c113011130443
711c1130511325214
89a91019130301
99a91319159292
109b92019211112
119b92129226153
129b92279249234
Consolidated


Thanks in advance
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi, well, this could get you the data into your format on Sheet2, but I can't see a way to order it in the way you have, as it doesn't seem logical.

VBA Code:
Sub consolidate_classes()

last_row = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row


For x = 1 To last_row

   
        last_row2 = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
        row_count = last_row2 + 1
    
        Text = Replace(UCase(Range("A" & x)), " ", "")
        Room = Mid(Text, 5, InStr(5, Text, "(") - 5)
        
        x = x + 1
    
        
        Do While Range("A" & x) = "" Or UCase(Range("A" & x)) = "ENTRANCE" Or UCase(Range("A" & x)) = "ABSTRACT"
        
            x = x + 1
                
        Loop
    
    
            For y = x + 1 To last_row
            
                next_text = UCase(Range("A" & y))
     
                                
                    If next_text <> "TOTAL" Then
                        Sheets("Sheet2").Range("E" & row_count) = Room 'store room number on Sheet2
                        Range("A" & y, "D" & y).Copy Sheets("Sheet2").Range("A" & row_count, "D" & row_count)
                        row_count = row_count + 1
                        x = x + 1
                    Else
                        x = x + 1
                        Exit For
                    End If
             Next y
                                                    
Next x

End Sub
 
Upvote 1
Solution
Hi, well, this could get you the data into your format on Sheet2, but I can't see a way to order it in the way you have, as it doesn't seem logical.

VBA Code:
Sub consolidate_classes()

last_row = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row


For x = 1 To last_row

  
        last_row2 = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
        row_count = last_row2 + 1
   
        Text = Replace(UCase(Range("A" & x)), " ", "")
        Room = Mid(Text, 5, InStr(5, Text, "(") - 5)
       
        x = x + 1
   
       
        Do While Range("A" & x) = "" Or UCase(Range("A" & x)) = "ENTRANCE" Or UCase(Range("A" & x)) = "ABSTRACT"
       
            x = x + 1
               
        Loop
   
   
            For y = x + 1 To last_row
           
                next_text = UCase(Range("A" & y))
    
                               
                    If next_text <> "TOTAL" Then
                        Sheets("Sheet2").Range("E" & row_count) = Room 'store room number on Sheet2
                        Range("A" & y, "D" & y).Copy Sheets("Sheet2").Range("A" & row_count, "D" & row_count)
                        row_count = row_count + 1
                        x = x + 1
                    Else
                        x = x + 1
                        Exit For
                    End If
             Next y
                                                   
Next x

End Sub
Thank You very much It worked fine. I have to only sort it to order it in the way I have.
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,980
Members
449,201
Latest member
Lunzwe73

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