Offset Help

keranali

Rules Violation
Joined
Oct 4, 2010
Messages
234
Office Version
  1. 365
Platform
  1. Windows
Hi all if I have cells with

a
a
b
b
cc
cc
cc
cc
d
ee

and want to create a 2 new rows between how do i go about that.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
keranali,


Sample raw data before the macro:


Excel Workbook
A
1a
2a
3b
4b
5cc
6cc
7cc
8cc
9d
10ee
11
Sheet1





After the macro:


Excel Workbook
A
1a
2a
3
4
5b
6b
7
8
9cc
10cc
11cc
12cc
13
14
15d
16
17
18ee
19
Sheet1





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 InsertTwo()
' hiker95, 03/31/2011
' http://www.mrexcel.com/forum/showthread.php?t=540316
Dim LR As Long, a As Long
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 1).End(xlUp).Row
For a = LR To 2 Step -1
  If Cells(a, 1) <> Cells(a - 1, 1) Then Rows(a).Resize(2).Insert
Next a
Application.ScreenUpdating = True
End Sub


Then run the InsertTwo macro.
 
Upvote 0
Wow thank you very much hiker, amazing you have saved me months of work thank you very much, there's one more thing how do you now auto sum the seperate values.

Thank you
Keran
 
Upvote 0
Excel Workbook
I
9165Plastic Sharpener 1 Hole
Items Sold to Customers
Excel 2007
 
Upvote 0
Hello Hiker this is a sample sheet the formula worked but i was vague and your formula referred to col A, can it work for col C (Item ID) also when it seperates can I get a auto sum of the values seperated in col F (amount)
Excel Workbook
ABCDEF
1Customer IDNameItem IDItem DescriptionQtyAmount
2A&R 01ABC2001000001006Star Copy, Copy Paper 8.5 x 142,400.0064,770.00
3A1OTLDEF2001000001006Star Copy, Copy Paper 8.5 x 14210.005,667.38
4A&R 01GHI2001000001009Star Copy, Copy Paper A43,760.0014,250.40
5ACADEMY 01JKL60-INDX-EW-000-0805INDEX CARDS 8 X 5 100/PACK3.0037.50
6A.S 01MNO61-GRAB-EW-000-001GRAPH BOOK SPIRAL 40LVS100.00400.00
7ACADEMY 01PQR61-PADP-EW-040-8511PADS 8.5 X 11 WHITE PERFORATED12.0054.00
8A.S 01STU61-SKTP-EW-000-1014SKETCH PAD 10 X 1480.00300.00
9ACADEMY 01VW6-RECB-EW-100-0604Receipt Books 2pt 6 X 4 100'S2.0019.00
10ACADEMY 01XY8-CLIP-PPR-003Ezy Clip Paper Clip Medium3.004.35
11ACADEMY 01Z8-ENVLOPE-MAN-007Manilla envelopes 12 x 15.5100.00110.00
12ACADEMY 01AZ8-ENVLOPE-WHT-009White window envelopes 4 1/8 x100.0018.00
Sheet1
Excel 2007
 
Upvote 0
Hi Hiker I am thinking something like this


Excel Workbook
ABCDEF
1Customer IDNameItem IDItem DescriptionQtyAmount
2A&R 01ABC2001000001006Star Copy, Copy Paper 8.5 x 142,400.0064,770.00
3A1OTLDEF2001000001006Star Copy, Copy Paper 8.5 x 14210.005,667.38
470,437.38
5
6A&R 01GHI2001000001009Star Copy, Copy Paper A43,760.0014,250.40
714,250.40
8
9ACADEMY 01JKL60-INDX-EW-000-0805INDEX CARDS 8 X 5 100/PACK3.0037.50
1037.50
11
12A.S 01MNO61-GRAB-EW-000-001GRAPH BOOK SPIRAL 40LVS100.00400.00
13400.00
14
15ACADEMY 01PQR61-PADP-EW-040-8511PADS 8.5 X 11 WHITE PERFORATED12.0054.00
1654.00
17
18A.S 01STU61-SKTP-EW-000-1014SKETCH PAD 10 X 1480.00300.00
19300.00
20
21ACADEMY 01VW6-RECB-EW-100-0604Receipt Books 2pt 6 X 4 100'S2.0019.00
2219.00
23
24ACADEMY 01XY8-CLIP-PPR-003Ezy Clip Paper Clip Medium3.004.35
254.35
26
27ACADEMY 01Z8-ENVLOPE-MAN-007Manilla envelopes 12 x 15.5100.00110.00
28110.00
29
30ACADEMY 01AZ8-ENVLOPE-WHT-009White window envelopes 4 1/8 x100.0018.00
31ACADEMY 01AZ8-ENVLOPE-WHT-009White window envelopes 4 1/8 x100.0018.00
3236.00
Sheet1



Thanks
 
Upvote 0
keranali,


Sample raw data before the macro:


Excel Workbook
ABCDEF
1Customer IDNameItem IDItem DescriptionQtyAmount
2A&R 01ABC2001000001006Star Copy, Copy Paper 8.5 x 142,400.0064,770.00
3A1OTLDEF2001000001006Star Copy, Copy Paper 8.5 x 142105,667.38
4A&R 01GHI2001000001009Star Copy, Copy Paper A43,760.0014,250.40
5ACADEMY *01JKL60-INDX-EW-000-0805INDEX CARDS 8 X 5 100/PACK337.5
6A.S 01MNO61-GRAB-EW-000-001GRAPH BOOK SPIRAL 40LVS100400
7ACADEMY *01PQR61-PADP-EW-040-8511PADS 8.5 X 11 WHITE PERFORATED1254
8A.S 01STU61-SKTP-EW-000-1014SKETCH PAD 10 X 1480300
9ACADEMY *01VW6-RECB-EW-100-0604Receipt Books 2pt 6 X 4 100'S219
10ACADEMY *01XY8-CLIP-PPR-003Ezy Clip Paper Clip Medium34.35
11ACADEMY *01Z8-ENVLOPE-MAN-007Manilla envelopes 12 x 15.5100110
12ACADEMY *01AZ8-ENVLOPE-WHT-009White window envelopes 4 1/8 x10018
13
Sheet1





After the macro:


Excel Workbook
ABCDEF
1Customer IDNameItem IDItem DescriptionQtyAmount
2A&R 01ABC2001000001006Star Copy, Copy Paper 8.5 x 142,400.0064,770.00
3A1OTLDEF2001000001006Star Copy, Copy Paper 8.5 x 142105,667.38
470,437.38
5
6A&R 01GHI2001000001009Star Copy, Copy Paper A43,760.0014,250.40
714,250.40
8
9ACADEMY *01JKL60-INDX-EW-000-0805INDEX CARDS 8 X 5 100/PACK337.5
1037.50
11
12A.S 01MNO61-GRAB-EW-000-001GRAPH BOOK SPIRAL 40LVS100400
13400.00
14
15ACADEMY *01PQR61-PADP-EW-040-8511PADS 8.5 X 11 WHITE PERFORATED1254
1654.00
17
18A.S 01STU61-SKTP-EW-000-1014SKETCH PAD 10 X 1480300
19300.00
20
21ACADEMY *01VW6-RECB-EW-100-0604Receipt Books 2pt 6 X 4 100'S219
2219.00
23
24ACADEMY *01XY8-CLIP-PPR-003Ezy Clip Paper Clip Medium34.35
254.35
26
27ACADEMY *01Z8-ENVLOPE-MAN-007Manilla envelopes 12 x 15.5100110
28110.00
29
30ACADEMY *01AZ8-ENVLOPE-WHT-009White window envelopes 4 1/8 x10018
3118.00
32
Sheet1





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 InsertTwoAndSum()
' hiker95, 03/31/2011
' http://www.mrexcel.com/forum/showthread.php?t=540316
Dim LR As Long, a As Long
Dim FArea As Range, SR As Long, ER As Long
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 3).End(xlUp).Row
For a = LR To 3 Step -1
  If Cells(a, 3) <> Cells(a - 1, 3) Then Rows(a).Resize(2).Insert
Next a
For Each FArea In Range("F2", Range("F" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With FArea
    SR = .Row
    ER = SR + .Rows.Count - 1
    With Range("F" & ER + 1)
      .Value = "=SUM(F" & SR & ":F" & ER & ")"
      .Font.Bold = True
      .NumberFormat = "#,##0.00"
    End With
  End With
Next FArea
Application.ScreenUpdating = True
End Sub


Then Save your workbook, Save As, a macro enabled workbook.


Then run the InsertTwoAndSum macro.
 
Upvote 0
keranali,


The following code will also give the totals in column F a yellow background color.


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 InsertTwoAndSum()
' hiker95, 03/31/2011
' http://www.mrexcel.com/forum/showthread.php?t=540316
Dim LR As Long, a As Long
Dim FArea As Range, SR As Long, ER As Long
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 3).End(xlUp).Row
For a = LR To 3 Step -1
  If Cells(a, 3) <> Cells(a - 1, 3) Then Rows(a).Resize(2).Insert
Next a
For Each FArea In Range("F2", Range("F" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With FArea
    SR = .Row
    ER = SR + .Rows.Count - 1
    With Range("F" & ER + 1)
      .Value = "=SUM(F" & SR & ":F" & ER & ")"
      .Font.Bold = True
      .NumberFormat = "#,##0.00"
      .Interior.Color = 65535
    End With
  End With
Next FArea
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Mr. Hiker thank you very much for this did you develop Microsoft excel? You must teach me how to do this.

Thank you very much
Happy easter
K
 
Upvote 0
keranali,

You are very welcome.


Training / Books / Sites:

MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
http://www.mrexcel.com/forum/forumdisplay.php?f=19

How to Learn to Write Macros
http://articles.excelyogi.com/playin...ba/2008/10/27/

How to use the macro recorder
http://articles.excelyogi.com/

Click here and scroll down to Getting Started with VBA.
http://www.datapigtechnologies.com/ExcelMain.htm

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm

Excel Tutorials and Tips - VBA - macros - training
http://www.mrexcel.com/articles.shtml

See David McRitchie's site if you just started with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Debra Dalgleish has some notes how to implement macros here:
Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

Creating custom functions
http://office.microsoft.com/en-us/excel/HA011117011033.aspx

Writing Your First VBA Function in Excel
http://www.exceltip.com/st/Writing_Your_First_VBA_Function_in_Excel/631.html

http://www.excel-vba.com/
http://www.mvps.org/dmcritchie/excel/getstarted.htm
http://www.exceltip.com/excel_links.html

(livelessons video)
Excel VBA and Macros with MrExcel
ISBN: 0-7897-3938-0
http://www.amazon.com/Excel-Macros-M...7936479&sr=1-1

http://www.youtube.com/user/ExcelIsFun#g/search

http://www.xl-central.com/index.html

http://www.datapigtechnologies.com/ExcelMain.htm

Dependent validation lists. Debra has a neat little tutorial here.
http://www.contextures.com/xlDataVal02.html

Data Validation > Drop-Down Lists - Dependent
http://www.bettersolutions.com/excel/EGH188/QE229212022.htm

Cascading queries
http://www.tushar-mehta.com/excel/ne...ing_dropdowns/

http://www.contextures.com/xlDataVal05.html

Excel Data Validation - Add New Items
http://www.contextures.com/excel-data-validation-add.html

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.
http://www.cpearson.com/Excel/vbe.aspx

Locating files containing VBA
Searching Files in Subfolders for VBA code string:
http://www.dailydoseofexcel.com/arch...a-code-string/

http://www.pcreview.co.uk/forums/thread-978054.php

Excel 2003 Power Programming with VBA, by John Walkenbach

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…
http://www.mrexcel.com/learnexcel2.shtml

DonkeyOte: My Recommended Reading:
Volatility
http://www.decisionmodels.com/calcsecretsi.htm

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Introduction to Array Formulas
http://www.xtremevbtalk.com/showthread.php?t=296012

Using Pivot Tables and Pivot Charts in Microsoft Excel
http://peltiertech.com/Excel/Pivots/pivotstart.htm

A List of Pivot Table links at Jon Peltier's site (contributed by Debra Dalgleish) is here:
http://peltiertech.com/Excel/Pivots/pivotlinks.htm

Email from XL - VBA & Outlook VBA
http://www.rondebruin.nl/sendmail.htm
http://www.outlookcode.com/article.aspx?ID=40

Excel Function Dictionary
http://www.xlfdic.com/

Excel 2007 function name translations
http://www.piuha.fi/excel-function-name-translation/

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

Where to paste code in VBE VBA
Introducing the Excel VBA Editor
http://www.ask.com/web?qsrc=2417&o=101881&l=dis&q=Where+to+paste+code+in+the+Excel+VBA+Editor

VBA for Excel (Macros)
http://www.excel-vba.com/excel-vba-contents.htm

VBA Lesson 11: VBA Code General Tips and General Vocabulary
http://www.excel-vba.com/vba-code-2-1-tips.htm

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

Basics of array formulas
http://www.youtube.com/view_play_lis...7E7E9CA63304D3

Array formula data extract formulas
http://www.youtube.com/watch?v=Tp7I5u1MqiM
http://www.youtube.com/watch?v=R5ZWAiNJLNo
http://www.youtube.com/watch?v=132ZdpxBm1U

How to create Excel Dashboards
http://www.contextures.com/excel-dashboards.html
http://chandoo.org/wp/excel-dashboards/

Unique Record Counting and Data Extract formulas
http://www.youtube.com/watch?v=uUrI8hoj8BA
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,920
Latest member
jaspers

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