LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default EASY - Excel VBA Problem

I have a macro (below) which performs the functions shown in the sample
spreadsheet (below). It works fine except that if instead of having
line 7 be another name you have line 7 be another "group" (ie. a group
immediately following a previous group) it doesn't work properly and
ignores the next group. This means to work there must be a row without
"group" or "group member" in it before the next "group" can work. How
do I handle one group (with members) immediately followed by another
group (with members)??? There can be a number of groups in a row before
a row without a group.

Any help would be really appreciated.

Thanks,

Andrew


ORIGINAL:
A B C D E F
1)[Name1] [data1][Address1][City1] [State1]
2)[Name2] "Group" [Address2][City2] [State2]
3)[Name3] "Group member" [data2]
4)[Name4] "Group member" [data3]
5)[Name5] "Group" [Address3][City3] [State3]
3)[Name6] "Group member" [data4]
4)[Name7] "Group member" [data5]
7)[Name8] [data6][Address4][City4] [State4]

Needed (after macro):
A B C D E
1)[Name1] [data1][Address1][City1] [State1]
3)[Name3] [data2][Address2][City2] [State2]
4)[Name4] [data3][Address2][City2] [State2]
5)[Name6] [data4][Address3][City3] [State3]
6)[Name7] [data5][Address3][City3] [State3]
7)[Name8] [data6][Address4][City4] [State4]

Sub Groups()
Dim Rng1 As Range, Rng2 As Range
Dim C As Range, DeleteRng As Range
Dim FirstAdd As String
Application.ScreenUpdating = False
Set Rng1 = ActiveSheet.Columns("B")
Set C = Rng1.Find("Group", LookIn:=xlValues)
If Not C Is Nothing Then
FirstAdd = C.Address
Set Rng2 = Range(C.Offset(, 2), C.Offset(, 10))
Do
Set C = C.Offset(1)
If LCase(Trim(C.Value)) = "group member" Then _
Range(C.Offset(, 2), C.Offset(, 10)) = Rng2.Value
Loop Until LCase(Trim(C.Value)) < "group member"
Set DeleteRng = Rng2.EntireRow
End If
Do
Set C = Rng1.FindNext(C)
If C.Address = FirstAdd Then Exit Do
Set Rng2 = Range(C.Offset(, 2), C.Offset(, 10))
Do
Set C = C.Offset(1)
If LCase(Trim(C.Value)) = "group member" Then _
Range(C.Offset(, 2), C.Offset(, 10)) = Rng2.Value
Loop Until LCase(Trim(C.Value)) < "group member"
Set DeleteRng = Union(DeleteRng, Rng2.EntireRow)
Loop While Not C Is Nothing
DeleteRng.Delete
Columns("B").EntireColumn.Delete
Application.ScreenUpdating = True
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Am I missing some easy solution to my problem? JJ Excel Worksheet Functions 2 September 17th 09 10:42 AM
Easy Problem that I can't figure out Cory from Eugene[_2_] Excel Discussion (Misc queries) 2 September 3rd 07 02:37 AM
OsCommerce - Easy Populate Script - CSV/TXT Conversion Problem. PriceTrim Excel Discussion (Misc queries) 3 July 5th 05 05:27 PM
VBA macro easy problem! Andrew Slentz Excel Programming 2 May 7th 04 06:39 AM
easy problem Newbie wan kenobi Excel Programming 2 February 5th 04 05:57 PM


All times are GMT +1. The time now is 06:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"