Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default pulling data from another sheet

I am in the very early stages of learning programming. Any help would be
greatly appreciated.
I am attempting to pull data from cells on another sheet, by using matching
reference numbers.

Basically how I am attempting to do this is to loop through all the item
numbers on the sheet.
The first attempt is match a 12 digit UPC number, and if that doesn't return
a match on the data sheet, then it should check a second number, which
happens to be 6 digits. I was able to get the first part to work, but then
when I tried to add the condition (When the 12 digit code is not found,
check the 6 digit one, my code is failing.

Code is as follows...

Sub ExtractData()

Dim rngSub As Range
Dim Cell As Range
Dim x As Range
Dim i As Integer
Dim y As String
On Error Resume Next
Application.ScreenUpdating = False


For i = 2 To ActiveWorkbook.Sheets.Count - 1
'makes loop skip data sheet

Set rngSub =
Sheets(i).Range("N:N").SpecialCells(xlCellTypeCons tants, 23)
'loop through all cells
For Each Cell In rngSub
'add the dash as the data sheet has dashes in the numbers
y = Left(Cell, 6) & "-" & Right(Cell, 6)
Debug.Print y
Set x = Sheets(1).Cells.Find(What:=y, LookAt:=xlPart)
Cell.Offset(0, 4).Value = x.Offset(0, 17).Value
Debug.Print x.Offset(0, 17).Value

'if 12 digit number does not match, attempt to find matching 5 digit number
If
Application.WorksheetFunction.CountBlank(Sheets(i) .Cell.Offset(0, 4)) = 1
Then
y = Left(Cell.Offset(0, -11), 3) & "-" &
Right(Cell.Offset(0, -11), 3)
Debug.Print y
Set x = Sheets(1).Cells.Find _
(What:=y, LookAt:=xlWhole)
Cell.Offset(0, 4).Value = x.Offset(0, 15)


Next Cell
MsgBox Sheets(i).Name
Application.ScreenUpdating = True
Next i

End Sub

Thanks in advance,

Ad108


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default pulling data from another sheet

Maybe try this (I haven't tested it, don't understand the data)

Sub ExtractData()

Dim rngSub As Range
Dim Cell As Range
Dim x As Range
Dim i As Integer
Dim y As String
On Error Resume Next
Application.ScreenUpdating = False


For i = 2 To ActiveWorkbook.Sheets.Count - 1
'makes loop skip data sheet

Set rngSub =
Sheets(i).Range("N:N").SpecialCells(xlCellTypeCons tants, 23)
'loop through all cells
For Each Cell In rngSub
'add the dash as the data sheet has dashes in the numbers
y = Left(Cell, 6) & "-" & Right(Cell, 6)
Debug.Print y
Set x = Sheets(1).Cells.Find(What:=y, LookAt:=xlPart)
If Not x Is Nothing Then
Cell.Offset(0, 4).Value = x.Offset(0, 17).Value
Debug.Print x.Offset(0, 17).Value
Else
'if 12 digit number does not match,
'attempt to find matching 5 digit number
y = Left(Cell.Offset(0, -11), 3) & "-" &
Right(Cell.Offset(0, -11), 3)
Debug.Print y
Set x = Sheets(1).Cells.Find _
(What:=y, LookAt:=xlWhole)
If Not x Is Nothing Then _
Cell.Offset(0, 4).Value = x.Offset(0, 15)
End If
Next Cell
MsgBox Sheets(i).Name
Application.ScreenUpdating = True
Next i

End Sub


BTW, best not to use constants when there is a declared constant available
(Specialcells value).

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"AD108" wrote in message
...
I am in the very early stages of learning programming. Any help would be
greatly appreciated.
I am attempting to pull data from cells on another sheet, by using

matching
reference numbers.

Basically how I am attempting to do this is to loop through all the item
numbers on the sheet.
The first attempt is match a 12 digit UPC number, and if that doesn't

return
a match on the data sheet, then it should check a second number, which
happens to be 6 digits. I was able to get the first part to work, but

then
when I tried to add the condition (When the 12 digit code is not found,
check the 6 digit one, my code is failing.

Code is as follows...

Sub ExtractData()

Dim rngSub As Range
Dim Cell As Range
Dim x As Range
Dim i As Integer
Dim y As String
On Error Resume Next
Application.ScreenUpdating = False


For i = 2 To ActiveWorkbook.Sheets.Count - 1
'makes loop skip data sheet

Set rngSub =
Sheets(i).Range("N:N").SpecialCells(xlCellTypeCons tants, 23)
'loop through all cells
For Each Cell In rngSub
'add the dash as the data sheet has dashes in the numbers
y = Left(Cell, 6) & "-" & Right(Cell, 6)
Debug.Print y
Set x = Sheets(1).Cells.Find(What:=y, LookAt:=xlPart)
Cell.Offset(0, 4).Value = x.Offset(0, 17).Value
Debug.Print x.Offset(0, 17).Value

'if 12 digit number does not match, attempt to find matching 5 digit

number
If
Application.WorksheetFunction.CountBlank(Sheets(i) .Cell.Offset(0, 4)) = 1
Then
y = Left(Cell.Offset(0, -11), 3) & "-" &
Right(Cell.Offset(0, -11), 3)
Debug.Print y
Set x = Sheets(1).Cells.Find _
(What:=y, LookAt:=xlWhole)
Cell.Offset(0, 4).Value = x.Offset(0, 15)


Next Cell
MsgBox Sheets(i).Name
Application.ScreenUpdating = True
Next i

End Sub

Thanks in advance,

Ad108




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default pulling data from another sheet

Thanks a alot,

That solved the problem


"Bob Phillips" wrote in message
...
Maybe try this (I haven't tested it, don't understand the data)

Sub ExtractData()

Dim rngSub As Range
Dim Cell As Range
Dim x As Range
Dim i As Integer
Dim y As String
On Error Resume Next
Application.ScreenUpdating = False


For i = 2 To ActiveWorkbook.Sheets.Count - 1
'makes loop skip data sheet

Set rngSub =
Sheets(i).Range("N:N").SpecialCells(xlCellTypeCons tants, 23)
'loop through all cells
For Each Cell In rngSub
'add the dash as the data sheet has dashes in the numbers
y = Left(Cell, 6) & "-" & Right(Cell, 6)
Debug.Print y
Set x = Sheets(1).Cells.Find(What:=y, LookAt:=xlPart)
If Not x Is Nothing Then
Cell.Offset(0, 4).Value = x.Offset(0, 17).Value
Debug.Print x.Offset(0, 17).Value
Else
'if 12 digit number does not match,
'attempt to find matching 5 digit number
y = Left(Cell.Offset(0, -11), 3) & "-" &
Right(Cell.Offset(0, -11), 3)
Debug.Print y
Set x = Sheets(1).Cells.Find _
(What:=y, LookAt:=xlWhole)
If Not x Is Nothing Then _
Cell.Offset(0, 4).Value = x.Offset(0, 15)
End If
Next Cell
MsgBox Sheets(i).Name
Application.ScreenUpdating = True
Next i

End Sub


BTW, best not to use constants when there is a declared constant available
(Specialcells value).

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"AD108" wrote in message
...
I am in the very early stages of learning programming. Any help would

be
greatly appreciated.
I am attempting to pull data from cells on another sheet, by using

matching
reference numbers.

Basically how I am attempting to do this is to loop through all the item
numbers on the sheet.
The first attempt is match a 12 digit UPC number, and if that doesn't

return
a match on the data sheet, then it should check a second number, which
happens to be 6 digits. I was able to get the first part to work, but

then
when I tried to add the condition (When the 12 digit code is not found,
check the 6 digit one, my code is failing.

Code is as follows...

Sub ExtractData()

Dim rngSub As Range
Dim Cell As Range
Dim x As Range
Dim i As Integer
Dim y As String
On Error Resume Next
Application.ScreenUpdating = False


For i = 2 To ActiveWorkbook.Sheets.Count - 1
'makes loop skip data sheet

Set rngSub =
Sheets(i).Range("N:N").SpecialCells(xlCellTypeCons tants, 23)
'loop through all cells
For Each Cell In rngSub
'add the dash as the data sheet has dashes in the numbers
y = Left(Cell, 6) & "-" & Right(Cell, 6)
Debug.Print y
Set x = Sheets(1).Cells.Find(What:=y, LookAt:=xlPart)
Cell.Offset(0, 4).Value = x.Offset(0, 17).Value
Debug.Print x.Offset(0, 17).Value

'if 12 digit number does not match, attempt to find matching 5 digit

number
If
Application.WorksheetFunction.CountBlank(Sheets(i) .Cell.Offset(0, 4)) =

1
Then
y = Left(Cell.Offset(0, -11), 3) & "-" &
Right(Cell.Offset(0, -11), 3)
Debug.Print y
Set x = Sheets(1).Cells.Find _
(What:=y, LookAt:=xlWhole)
Cell.Offset(0, 4).Value = x.Offset(0, 15)


Next Cell
MsgBox Sheets(i).Name
Application.ScreenUpdating = True
Next i

End Sub

Thanks in advance,

Ad108






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
Pulling data from one sheet to another Jeremy Excel Discussion (Misc queries) 1 May 26th 09 02:58 PM
Pulling Data from another sheet [email protected] Excel Discussion (Misc queries) 0 September 17th 07 04:26 PM
pulling data from one sheet to another RPW New Users to Excel 12 February 20th 07 05:04 PM
pulling data from another sheet HouseofRahl Excel Discussion (Misc queries) 2 July 21st 06 11:11 PM
Pulling data from 1 sheet to another Dave1155 Excel Worksheet Functions 1 January 12th 05 05:55 PM


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