Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA macro easy problem!

I have a macro (below) that copys the address info. for each "group"
designated in column B to each "group member". This works but for some
reason I am losing the info. in the C column for the group members. I
am also lost on how to get this to work if there are additional columns
of information beyond F. Any ideas???

The code:
Sub FixData()
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(, 1), C.Offset(, 5))
Do
Set C = C.Offset(1)
If LCase(Trim(C.Value)) = "group member" Then _
Range(C.Offset(, 1), C.Offset(, 4)) = 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(, 1), C.Offset(, 5))
Do
Set C = C.Offset(1)
If LCase(Trim(C.Value)) = "group member" Then _
Range(C.Offset(, 1), C.Offset(, 4)) = 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


Here is an example:
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 member" [data4]
6)[Name6] "Group member" [data5]
7)[Name7] [data6][Address3][City3] [State3]

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)[Name5] [data4][Address2][City2] [State2]
6)[Name6] [data5][Address2][City2] [State2]
7)[Name7] [data6][Address3][City3] [State3]

Thanks!!!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default VBA macro easy problem!

How about rewritting the macro? Try the following macro

'---------------------------------------------------
Sub FixData(
Dim c As Object, tmp As Singl
With Selection.CurrentRegio
If .Rows.Count 1 The
For Each c In .Column
For tmp = 2 To .Rows.Coun
If c.Cells(tmp).Value = "" Then c.Cells(tmp).Value = c.Cells(tmp - 1).Valu
Nex
Nex
End I
.Columns(2).EntireColumn.Delet
End Wit
End Su
'---------------------------------------------------

Regards
Edwin Ta

http://www.vonixx.co


----- Andrew Slentz wrote: ----

I have a macro (below) that copys the address info. for each "group
designated in column B to each "group member". This works but for som
reason I am losing the info. in the C column for the group members.
am also lost on how to get this to work if there are additional column
of information beyond F. Any ideas??

The code
Sub FixData(
Dim Rng1 As Range, Rng2 As Rang
Dim C As Range, DeleteRng As Rang
Dim FirstAdd As Strin

Application.ScreenUpdating = Fals

Set Rng1 = ActiveSheet.Columns("B"
Set C = Rng1.Find("Group", LookIn:=xlValues
If Not C Is Nothing The
FirstAdd = C.Addres
Set Rng2 = Range(C.Offset(, 1), C.Offset(, 5)
D
Set C = C.Offset(1
If LCase(Trim(C.Value)) = "group member" Then
Range(C.Offset(, 1), C.Offset(, 4)) = Rng2.Valu
Loop Until LCase(Trim(C.Value)) < "group member
Set DeleteRng = Rng2.EntireRo
End I

D
Set C = Rng1.FindNext(C
If C.Address = FirstAdd Then Exit D
Set Rng2 = Range(C.Offset(, 1), C.Offset(, 5)
D
Set C = C.Offset(1
If LCase(Trim(C.Value)) = "group member" Then
Range(C.Offset(, 1), C.Offset(, 4)) = Rng2.Valu
Loop Until LCase(Trim(C.Value)) < "group member
Set DeleteRng = Union(DeleteRng, Rng2.EntireRow
Loop While Not C Is Nothin
DeleteRng.Delet
Columns("B").EntireColumn.Delet

Application.ScreenUpdating = Tru

End Su


Here is an example
A B C D E
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 member" [data4
6)[Name6] "Group member" [data5
7)[Name7] [data6][Address3][City3] [State3

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

Thanks!!



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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default VBA macro easy problem!

See my response to your original post.

Regards,
Greg

Reply
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
Macro Help, Real Easy comotoman Excel Discussion (Misc queries) 4 January 30th 06 03:43 PM
OsCommerce - Easy Populate Script - CSV/TXT Conversion Problem. PriceTrim Excel Discussion (Misc queries) 3 July 5th 05 05:27 PM
easy problem Newbie wan kenobi Excel Programming 2 February 5th 04 05:57 PM


All times are GMT +1. The time now is 09: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"