PC Review


Reply
Thread Tools Rate Thread

Correlating rows on different sheets

 
 
GSBrown123@googlemail.com
Guest
Posts: n/a
 
      17th Mar 2008
Hi,

First of all apologies for the title of my post. I really don't know
what the name of the function is that I'm trying to achieve.

I'm trying get a macro to correlate data that appear on 2 separate
sheets and transfer the relevant data over.
For example...

Sheet 1 has dozens of lines of data spread over several columns which
is updated daily.
Column A in sheet 1 contains a number. For easy I'll call it a P
number. The same number is also found in sheet 2 in column C. The P
number in sheet 2 column C can sometimes have a letter before it and
sometimes after but it is number that is the reference and is the same
P number in sheet 1 column A.
I need a macro to run daily when requested to take the P number in
sheet 1 column A for each line and find the same P number (discounting
any letters present in the cell) in sheet 2 column C.
For each P number in sheet 1 column A it needs to remove data from
sheet 2 colums G to T and copy it into the end columns of sheet 1 on
the rows of the relvant P number from sheet 2.
For every P number in sheet 1 column A there may not be a P number in
sheet 2 column F. If this is the case the new columns in sheet 1
should read "No Data".

Thanks
G
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      17th Mar 2008
Your posting for sheet 2 has both colun c and Column F as the search column.
which one is correct?


Sh1RowCount = 1
With Sheets("Sheet1")
Do While .Range("A" & Sh1RowCount) <> ""
find_Num = .Range("A" & Sh1RowCount)
With Sheets("Sheet2")
Found = False
Sh2RowCount = 1
Do While .Range("C" & Sh2RowCount) <> ""
OldNum = .Range("C" & Sh2RowCount)
'remove characters from number
NewNum = ""
Do While OldNum <> ""
If IsNumeric(Left(OldNum, 1)) Then
NewNum = NewNum & Left(OldNum, 1)
End If
If Len(OldNum) > 1 Then
OldNum = Mid(OldNum, 2)
Else
OldNum = ""
End If
Loop
NewNum = Val(NewNum)
If find_Num = NewNum Then
Found = True
.Range("G" & Sh2RowCount & ":T" & Sh2RowCount).Copy
Exit Do
End If
Sh2RowCount = Sh2RowCount + 1
Loop
End With

LastCol = .Cells(Sh1RowCount, Columns.Count).End(xlToLeft).Column
NewCol = LastCol + 1
If Found = False Then
.Cells(Sh1RowCount, NewCol) = "No Data"
Else
Sheets("Sheet2").Range("G" & Sh2RowCount & ":T" & Sh2RowCount).Copy _
Destination:=.Cells(Sh1RowCount, NewCol)
End If
Sh1RowCount = Sh1RowCount + 1
Loop
End With

"(E-Mail Removed)" wrote:

> Hi,
>
> First of all apologies for the title of my post. I really don't know
> what the name of the function is that I'm trying to achieve.
>
> I'm trying get a macro to correlate data that appear on 2 separate
> sheets and transfer the relevant data over.
> For example...
>
> Sheet 1 has dozens of lines of data spread over several columns which
> is updated daily.
> Column A in sheet 1 contains a number. For easy I'll call it a P
> number. The same number is also found in sheet 2 in column C. The P
> number in sheet 2 column C can sometimes have a letter before it and
> sometimes after but it is number that is the reference and is the same
> P number in sheet 1 column A.
> I need a macro to run daily when requested to take the P number in
> sheet 1 column A for each line and find the same P number (discounting
> any letters present in the cell) in sheet 2 column C.
> For each P number in sheet 1 column A it needs to remove data from
> sheet 2 colums G to T and copy it into the end columns of sheet 1 on
> the rows of the relvant P number from sheet 2.
> For every P number in sheet 1 column A there may not be a P number in
> sheet 2 column F. If this is the case the new columns in sheet 1
> should read "No Data".
>
> Thanks
> G
>

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      17th Mar 2008
I had one extra line in my porevious code that does no harm, but should be
removed

Sh1RowCount = 1
With Sheets("Sheet1")
Do While .Range("A" & Sh1RowCount) <> ""
find_Num = .Range("A" & Sh1RowCount)
With Sheets("Sheet2")
Found = False
Sh2RowCount = 1
Do While .Range("C" & Sh2RowCount) <> ""
OldNum = .Range("C" & Sh2RowCount)
'remove characters from number
NewNum = ""
Do While OldNum <> ""
If IsNumeric(Left(OldNum, 1)) Then
NewNum = NewNum & Left(OldNum, 1)
End If
If Len(OldNum) > 1 Then
OldNum = Mid(OldNum, 2)
Else
OldNum = ""
End If
Loop
NewNum = Val(NewNum)
If find_Num = NewNum Then
Found = True
Exit Do
End If
Sh2RowCount = Sh2RowCount + 1
Loop
End With

LastCol = .Cells(Sh1RowCount, Columns.Count).End(xlToLeft).Column
NewCol = LastCol + 1
If Found = False Then
.Cells(Sh1RowCount, NewCol) = "No Data"
Else
Sheets("Sheet2").Range("G" & Sh2RowCount & ":T" & Sh2RowCount).Copy _
Destination:=.Cells(Sh1RowCount, NewCol)
End If
Sh1RowCount = Sh1RowCount + 1
Loop
End With

"(E-Mail Removed)" wrote:

> Hi,
>
> First of all apologies for the title of my post. I really don't know
> what the name of the function is that I'm trying to achieve.
>
> I'm trying get a macro to correlate data that appear on 2 separate
> sheets and transfer the relevant data over.
> For example...
>
> Sheet 1 has dozens of lines of data spread over several columns which
> is updated daily.
> Column A in sheet 1 contains a number. For easy I'll call it a P
> number. The same number is also found in sheet 2 in column C. The P
> number in sheet 2 column C can sometimes have a letter before it and
> sometimes after but it is number that is the reference and is the same
> P number in sheet 1 column A.
> I need a macro to run daily when requested to take the P number in
> sheet 1 column A for each line and find the same P number (discounting
> any letters present in the cell) in sheet 2 column C.
> For each P number in sheet 1 column A it needs to remove data from
> sheet 2 colums G to T and copy it into the end columns of sheet 1 on
> the rows of the relvant P number from sheet 2.
> For every P number in sheet 1 column A there may not be a P number in
> sheet 2 column F. If this is the case the new columns in sheet 1
> should read "No Data".
>
> Thanks
> G
>

 
Reply With Quote
 
GSBrown123@googlemail.com
Guest
Posts: n/a
 
      4th Apr 2008
On Mar 17, 7:05*pm, Joel <J...@discussions.microsoft.com> wrote:
> I had one extra line in my porevious code that does no harm, but should be
> removed
>
> Sh1RowCount = 1
> With Sheets("Sheet1")
> * *Do While .Range("A" & Sh1RowCount) <> ""
> * * * find_Num = .Range("A" & Sh1RowCount)
> * * * With Sheets("Sheet2")
> * * * * *Found = False
> * * * * *Sh2RowCount = 1
> * * * * *Do While .Range("C" & Sh2RowCount) <> ""
> * * * * * * OldNum = .Range("C" & Sh2RowCount)
> * * * * * * 'remove characters from number
> * * * * * * NewNum = ""
> * * * * * * Do While OldNum <> ""
> * * * * * * * *If IsNumeric(Left(OldNum, 1)) Then
> * * * * * * * * * NewNum = NewNum & Left(OldNum, 1)
> * * * * * * * *End If
> * * * * * * * *If Len(OldNum) > 1 Then
> * * * * * * * * * OldNum = Mid(OldNum, 2)
> * * * * * * * *Else
> * * * * * * * * * OldNum = ""
> * * * * * * * *End If
> * * * * * * Loop
> * * * * * * NewNum = Val(NewNum)
> * * * * * * If find_Num = NewNum Then
> * * * * * * * *Found = True
> * * * * * * * *Exit Do
> * * * * * * End If
> * * * * * * Sh2RowCount = Sh2RowCount + 1
> * * * * *Loop
> * * * End With
>
> * * * LastCol = .Cells(Sh1RowCount, Columns.Count).End(xlToLeft).Column
> * * * NewCol = LastCol + 1
> * * * If Found = False Then
> * * * * *.Cells(Sh1RowCount, NewCol) = "No Data"
> * * * Else
> * * * * *Sheets("Sheet2").Range("G" & Sh2RowCount & ":T" & Sh2RowCount).Copy _
> * * * * * * Destination:=.Cells(Sh1RowCount, NewCol)
> * * * End If
> * * * Sh1RowCount = Sh1RowCount + 1
> * *Loop
> End With
>
>
>
> "GSBrown...@googlemail.com" wrote:
> > Hi,

>
> > First of all apologies for the title of my post. I really don't know
> > what the name of the function is that I'm trying to achieve.

>
> > I'm trying get a macro to correlate data that appear on 2 separate
> > sheets and transfer the relevant data over.
> > For example...

>
> > Sheet 1 has dozens of lines of data spread over several columns which
> > is updated daily.
> > Column A in sheet 1 contains a number. For easy I'll call it a P
> > number. The same number is also found in sheet 2 in column C. The P
> > number in sheet 2 column C can sometimes have a letter before it and
> > sometimes after but it is number that is the reference and is the same
> > P number in sheet 1 column A.
> > I need a macro to run daily when requested to take the P number in
> > sheet 1 column A for each line and find the same P number (discounting
> > any letters present in the cell) in sheet 2 column C.
> > For each P number in sheet 1 column A it needs to remove data from
> > sheet 2 colums G to T and copy it into the end columns of sheet 1 on
> > the rows of the relvant P number from sheet 2.
> > For every P number in sheet 1 column A there may not be a P number in
> > sheet 2 column F. If this is the case the new columns in sheet 1
> > should read "No Data".

>
> > Thanks
> > G- Hide quoted text -

>
> - Show quoted text -



Thank Joel

The correct column is F.

I've tried the code but can't get it to work.

Please can you define any integers/variables/strings etc that you have
used at the beginning of the code please.

George
 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      4th Apr 2008
I assume you are not getting any errors?

Usually code like this doesn't work because of blank cells. The code stops
running when it finds the first blank cells in Sheet1 in column A and column
c in Sheet2.

The two lines below have to be set for the first row where data is found.
If row one doesn't contain data then that is why the code doesn't work.

Sh1RowCount = 1
Sh2RowCount = 1







"(E-Mail Removed)" wrote:

> On Mar 17, 7:05 pm, Joel <J...@discussions.microsoft.com> wrote:
> > I had one extra line in my porevious code that does no harm, but should be
> > removed
> >
> > Sh1RowCount = 1
> > With Sheets("Sheet1")
> > Do While .Range("A" & Sh1RowCount) <> ""
> > find_Num = .Range("A" & Sh1RowCount)
> > With Sheets("Sheet2")
> > Found = False
> > Sh2RowCount = 1
> > Do While .Range("C" & Sh2RowCount) <> ""
> > OldNum = .Range("C" & Sh2RowCount)
> > 'remove characters from number
> > NewNum = ""
> > Do While OldNum <> ""
> > If IsNumeric(Left(OldNum, 1)) Then
> > NewNum = NewNum & Left(OldNum, 1)
> > End If
> > If Len(OldNum) > 1 Then
> > OldNum = Mid(OldNum, 2)
> > Else
> > OldNum = ""
> > End If
> > Loop
> > NewNum = Val(NewNum)
> > If find_Num = NewNum Then
> > Found = True
> > Exit Do
> > End If
> > Sh2RowCount = Sh2RowCount + 1
> > Loop
> > End With
> >
> > LastCol = .Cells(Sh1RowCount, Columns.Count).End(xlToLeft).Column
> > NewCol = LastCol + 1
> > If Found = False Then
> > .Cells(Sh1RowCount, NewCol) = "No Data"
> > Else
> > Sheets("Sheet2").Range("G" & Sh2RowCount & ":T" & Sh2RowCount).Copy _
> > Destination:=.Cells(Sh1RowCount, NewCol)
> > End If
> > Sh1RowCount = Sh1RowCount + 1
> > Loop
> > End With
> >
> >
> >
> > "GSBrown...@googlemail.com" wrote:
> > > Hi,

> >
> > > First of all apologies for the title of my post. I really don't know
> > > what the name of the function is that I'm trying to achieve.

> >
> > > I'm trying get a macro to correlate data that appear on 2 separate
> > > sheets and transfer the relevant data over.
> > > For example...

> >
> > > Sheet 1 has dozens of lines of data spread over several columns which
> > > is updated daily.
> > > Column A in sheet 1 contains a number. For easy I'll call it a P
> > > number. The same number is also found in sheet 2 in column C. The P
> > > number in sheet 2 column C can sometimes have a letter before it and
> > > sometimes after but it is number that is the reference and is the same
> > > P number in sheet 1 column A.
> > > I need a macro to run daily when requested to take the P number in
> > > sheet 1 column A for each line and find the same P number (discounting
> > > any letters present in the cell) in sheet 2 column C.
> > > For each P number in sheet 1 column A it needs to remove data from
> > > sheet 2 colums G to T and copy it into the end columns of sheet 1 on
> > > the rows of the relvant P number from sheet 2.
> > > For every P number in sheet 1 column A there may not be a P number in
> > > sheet 2 column F. If this is the case the new columns in sheet 1
> > > should read "No Data".

> >
> > > Thanks
> > > G- Hide quoted text -

> >
> > - Show quoted text -

>
>
> Thank Joel
>
> The correct column is F.
>
> I've tried the code but can't get it to work.
>
> Please can you define any integers/variables/strings etc that you have
> used at the beginning of the code please.
>
> George
>

 
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
MACRO THAT CUT ROWS BETWEEN SHEETS AND ADD EMPTY ROWS udi Hen Microsoft Excel Programming 0 18th Dec 2008 02:41 PM
"Add/Remove Rows Code" adds rows on grouped sheets, but won't remove rows. Conan Kelly Microsoft Excel Programming 1 16th Nov 2007 10:41 PM
"With Sheets" Issue - macro on one sheet to affect hidden rows on other sheets Punsterr Microsoft Excel Programming 3 21st Feb 2006 04:01 AM
linking rows on sheets without empty rows in between Frank L Microsoft Excel Misc 0 17th Aug 2004 06:58 PM
Re: correlating data John Spencer (MVP) Microsoft Access VBA Modules 0 1st Aug 2003 12:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:33 PM.