PC Review


Reply
Thread Tools Rate Thread

Copying data from different column

 
 
maryj
Guest
Posts: n/a
 
      6th May 2009
I have data such as:

GLN Master SAP
1234 3333
4444
4567 7878
8888
9999
6789 4545
3535

This was created from a pivot. At each change in GLN (Col A) I need it to
select the first value in SAP (Col C) and paste in all rows for the group in
the Master column (Col B) The result like:
1234 3333 3333
3333 4444
4567 7878 7878
7878 8888
7878 9999
6789 4545 4545
4545 3535

the number of rows for each GLN group will vary - usually 2 but sometimes
more.

Thanks for you help!!

--
maryj
 
Reply With Quote
 
 
 
 
meh2030@gmail.com
Guest
Posts: n/a
 
      6th May 2009
On May 6, 8:56*am, maryj <ma...@discussions.microsoft.com> wrote:
> I have data such as:
>
> GLN * * * *Master * * *SAP
> 1234 * * * * * * * * * * *3333
> * * * * * * * * * * * * * * *4444
> 4567 * * * * * * * * * * *7878
> * * * * * * * * * * * * * * *8888
> * * * * * * * * * * * * * * *9999
> 6789 * * * * * * * * * * *4545
> * * * * * * * * * * * * * * *3535
>
> This was created from a pivot. At each change in GLN (Col A) I need it to
> select the first value in SAP (Col C) and paste in all rows for the groupin
> the Master column (Col B) The result like:
> 1234 * * 3333 * * * * *3333
> * * * * * * 3333 * * * * *4444
> 4567 * * 7878 * * * * *7878
> * * * * * * 7878 * * * * *8888
> * * * * * * 7878 * * * * *9999
> 6789 * * 4545 * * * * *4545
> * * * * * * 4545 * * * * *3535
>
> the number of rows for each GLN group will vary - usually 2 but sometimes
> more.
>
> Thanks for you help!!
>
> --
> maryj


MaryJ,

See the code below.

Best,

Matthew Herbert

Sub FillMaster()
Dim lngCnt As Long
Dim rngGLN As Range
Dim rngSAP As Range
Dim rngCell As Range
Dim intOffset As Integer

'assuming "SAP" is in C1
lngCnt = Range(Range("C1"), Range("C1").End(xlDown)).Rows.Count

'offset column from GLN
intOffset = 2

'create range object to loop through
Set rngGLN = Range(Range("A2"), Range("A" & lngCnt))

'loop through each cell in GLN
For Each rngCell In rngGLN.Cells

'if the cell is not blank then get the corresponding SAP value
If rngCell <> "" Then
Set rngSAP = rngCell.Offset(0, intOffset)
End If

'output the SAP value into Master
rngCell.Offset(0, intOffset - 1).Value = rngSAP.Value
Next

End Sub
 
Reply With Quote
 
maryj
Guest
Posts: n/a
 
      6th May 2009
Perfect!!!

Thanks so much!
--
maryj


"(E-Mail Removed)" wrote:

> On May 6, 8:56 am, maryj <ma...@discussions.microsoft.com> wrote:
> > I have data such as:
> >
> > GLN Master SAP
> > 1234 3333
> > 4444
> > 4567 7878
> > 8888
> > 9999
> > 6789 4545
> > 3535
> >
> > This was created from a pivot. At each change in GLN (Col A) I need it to
> > select the first value in SAP (Col C) and paste in all rows for the group in
> > the Master column (Col B) The result like:
> > 1234 3333 3333
> > 3333 4444
> > 4567 7878 7878
> > 7878 8888
> > 7878 9999
> > 6789 4545 4545
> > 4545 3535
> >
> > the number of rows for each GLN group will vary - usually 2 but sometimes
> > more.
> >
> > Thanks for you help!!
> >
> > --
> > maryj

>
> MaryJ,
>
> See the code below.
>
> Best,
>
> Matthew Herbert
>
> Sub FillMaster()
> Dim lngCnt As Long
> Dim rngGLN As Range
> Dim rngSAP As Range
> Dim rngCell As Range
> Dim intOffset As Integer
>
> 'assuming "SAP" is in C1
> lngCnt = Range(Range("C1"), Range("C1").End(xlDown)).Rows.Count
>
> 'offset column from GLN
> intOffset = 2
>
> 'create range object to loop through
> Set rngGLN = Range(Range("A2"), Range("A" & lngCnt))
>
> 'loop through each cell in GLN
> For Each rngCell In rngGLN.Cells
>
> 'if the cell is not blank then get the corresponding SAP value
> If rngCell <> "" Then
> Set rngSAP = rngCell.Offset(0, intOffset)
> End If
>
> 'output the SAP value into Master
> rngCell.Offset(0, intOffset - 1).Value = rngSAP.Value
> Next
>
> End Sub
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying data from 205 columns to 1 column Zuo Microsoft Excel Worksheet Functions 4 22nd Feb 2010 04:18 PM
Copying Data Down the Column But Only Based on What's in Column A childofthe1980s Microsoft Excel Programming 1 24th Dec 2009 01:50 PM
Copying Data into Column with Existing Data =?Utf-8?B?R1p1bA==?= Microsoft Excel Misc 0 9th Feb 2006 11:30 PM
Copying a formula in a blank column as far as data in previous column basildon Microsoft Excel Programming 1 16th Dec 2005 03:32 PM
Copying Column Data and Pasting it into a Row Hulk Microsoft Excel Misc 3 19th Oct 2004 11:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:51 AM.