Excel help

rrajansg

New Member
Joined
Mar 17, 2011
Messages
12
I downloaded the following information in txt format and converted into excel.

Available
Department A

Salaries 2
Rent 3
Legal 4

Department B

Salaries 34
Rent 25
Legal 38


Need information like this in Excel. Any help in excel formula or macro

Department A Rent 3
Department B Rent 25
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
rrajansg,

Welcome to the MrExcel forum.


What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples directly in the forum.

Please attach screenshots of your workbook or a sample workbook that accurately portrays your current workbook on one sheet, and what it should look like 'After' on another sheet.

This makes it much easier to see exactly what you want to do, as well as shows us whether there is a consistent number of rows between tables and such.

Here are three possible ways to post small (copyable) screen shots directly in your post:

Please post a screenshot of your sheet(s), what you have and what you expect to achieve, with Excel Jeanie HTML 4 (contains graphic instructions).
http://www.excel-jeanie-html.de/html/hlp_schnell_en.php

or
RichardSchollar’s beta HTML Maker -...his signature block at the bottom of his post

or
Borders-Copy-Paste



If you are not able to give us screenshots:

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
It looks like the data is contained in a single column. If this is case, assuming that Column A contains the data, try the following macro which will list the desired result starting at C2...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] test()

    [color=darkblue]Dim[/color] MyData() [color=darkblue]As[/color] [color=darkblue]Variant[/color]
    [color=darkblue]Dim[/color] LastRow [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] i [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] Cnt [color=darkblue]As[/color] [color=darkblue]Long[/color]
    
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    [color=darkblue]For[/color] i = 2 [color=darkblue]To[/color] LastRow
        [color=darkblue]If[/color] InStr(1, Cells(i, "A").Value, "Department") > 0 [color=darkblue]Then[/color]
            Cnt = Cnt + 1
            [color=darkblue]ReDim[/color] [color=darkblue]Preserve[/color] MyData(1 [color=darkblue]To[/color] 2, 1 To Cnt)
            MyData(1, Cnt) = Cells(i, "A").Value
        [color=darkblue]ElseIf[/color] InStr(1, Cells(i, "A").Value, "Rent") > 0 [color=darkblue]Then[/color]
            MyData(2, Cnt) = Cells(i, "A").Value
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] i
    
    Range("C2").Resize(UBound(MyData, 2), UBound(MyData, 1)) = WorksheetFunction.Transpose(MyData)
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0
Thanks Domenic

Data is in two columns( one column description and another column figures. But header is one column. After few rows another department information starts. Like this I have many department.

I have to summarise expenses for all departments.

I tried to attach my excel, but could not.

Now I have uploaded in the following link

http://www.rajenconsultancy.com/excel/

file name : test_1

Thanks in advance
 
Upvote 0
rrajansg,

Thanks for the workbook.


Sample raw data in column B of worksheet Sheet1:


Excel Workbook
BC
1
2
3Department A
4
5Salaries2
6Rent3
7Legal4
8
9
10Department B
11
12Salaries34
13Rent25
14Legal38
15
Sheet1





After the macro in a new worksheet Results:


Excel Workbook
ABC
1
2Department ARent3
3Department BRent25
4
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 ReorgData()
' hiker95, 03/17/2011
' http://www.mrexcel.com/forum/showthread.php?t=536941
Dim w1 As Worksheet, wR As Worksheet
Dim c As Range, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
Set wR = Worksheets("Results")
For Each c In w1.Range("B1", w1.Range("B" & Rows.Count).End(xlUp))
  If InStr(c, "Department") > 0 Then
    NR = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    wR.Cells(NR, 1) = c.Value
  ElseIf InStr(c, "Rent") > 0 Then
    wR.Cells(NR, 2) = c.Value
    wR.Cells(NR, 3) = c.Offset(, 1).Value
  End If
Next c
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub


Then run the ReorgData macro.
 
Upvote 0
rrajansg,


The same raw data screenshot as my previous reply.


After the updated macro in worksheet Results:


Excel Workbook
ABCD
1DepartmentSalariesRentLegal
2Department A234
3Department B342538
4
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).


Code:
Option Explicit
Sub ReorgDataV2()
' hiker95, 03/17/2011
' http://www.mrexcel.com/forum/showthread.php?t=536941
Dim w1 As Worksheet, wR As Worksheet
Dim c As Range, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
Set wR = Worksheets("Results")
wR.Range("A1:D1") = [{"Department","Salaries","Rent","Legal"}]
For Each c In w1.Range("B1", w1.Range("B" & Rows.Count).End(xlUp))
  If InStr(c, "Department") > 0 Then
    NR = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    wR.Cells(NR, 1) = c.Value
  ElseIf InStr(c, "Salaries") > 0 Then
    wR.Cells(NR, 2) = c.Offset(, 1).Value
  ElseIf InStr(c, "Rent") > 0 Then
    wR.Cells(NR, 3) = c.Offset(, 1).Value
  ElseIf InStr(c, "Legal") > 0 Then
    wR.Cells(NR, 4) = c.Offset(, 1).Value
  End If
Next c
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub


Then run the ReorgDataV2 macro.
 
Upvote 0
Thanks hiker95

I choose second option. It works perfect and I get what I want. You saved a day of my life every month.

Have a great day.

Thanks Domenic for your quick help.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,716
Members
452,939
Latest member
WCrawford

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