Computing.Net > Forums > Programming > VBA Excel

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBA Excel

Reply to Message Icon

Name: xcyperx
Date: November 24, 2008 at 12:57:34 Pacific
OS: XP
CPU/Ram: Pentium
Product: Dell
Comment:

Hi There,

I have a simple request but since my programming knowledge in VBA for excel is limited I don't really know where to start.

In excel, I have a column say A1:A100 which contains data that may or may not match. Basically I've sorted this data so all matching data is clumped.

What I want to do: Sorting and clumping aside, I'd like a macro that will look at the values in the column and if the value in A1 does not match in A2 to insert an entire row between A1 and A1. If the values do match, it should continue going down the column.

I hope this is enough information, thanks for your help in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: GhostWolf
Date: November 25, 2008 at 07:37:33 Pacific
Reply:

You could use a modification of the following code:

Const Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Public Function AddRows(prmRow As Range)
Dim c1 As String, c2 As String, c3 As String
Dim tgt As String
c1 = Mid(Letters, prmRow.Column, 1)
c2 = Mid(Letters, prmRow.Column + 2, 1)
c3 = CStr(prmRow.Row)
tgt = c1 & c3 & ":" & c2 & c3
ActiveSheet.Range(tgt).Insert xlShiftDown
End Function


This code inserts a blank row at [prmRow.Row], shifting everything in columns A through C down. It's just a quick-and-dirty test to teach me something new, so you may need to modify it severely to make it work for you.

"There are two things which are infinite: the universe and human stupidity - and I'm not so sure about the former." ~ Albert Einstein


0

Response Number 2
Name: xcyperx
Date: December 4, 2008 at 09:45:12 Pacific
Reply:

Hi, I figured it out after just running through a few programming guides. I'm trained in C++ so I just needed to figure out the syntax. This is the code i used below.

Sub Spacing()
Dim Counter
Counter = 1
Do While Cells(Counter, 1) <> ""
Do Until Cells(Counter, 1) <> Cells(Counter + 1, 1)
Counter = Counter + 1
Loop
Cells(Counter + 1, 1).EntireRow.Insert Shift:=xlDown
Counter = Counter + 2
Loop
End Sub


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBA Excel

VBA (Excel) Editing Cells www.computing.net/answers/programming/vba-excel-editing-cells/4698.html

VBA/Excel Dynamic cell reference www.computing.net/answers/programming/vbaexcel-dynamic-cell-reference/15585.html

VBA File export www.computing.net/answers/programming/vba-file-export/5046.html