Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Value not matching

I am running a loop to obtain values on a change event yet I can not seem to
obtain that value from the sheet I am looking at the values are returning a
blank?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim x As Integer

If Target.Address = "$C$13" Then
ItemNum = Target.Value

Sheets("Data").Select

For x = 1 To 10

If Cells(x, 1) = ItemNum Then
Desc = Cells(x, 2)
StdCost = Cells(x, 3)
Spec = Cells(x, 6)
End If

Next x

Sheets("Justification - working").Select

Cells(13, 4) = Desc
Cells(13, 6) = StdCost
Cells(13, 5) = Spec
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Value not matching

cells(x,1) is equals a "blank" yet there are values in the cells it is
looking at in the loop?

"Rpettis31" wrote:

I am running a loop to obtain values on a change event yet I can not seem to
obtain that value from the sheet I am looking at the values are returning a
blank?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim x As Integer

If Target.Address = "$C$13" Then
ItemNum = Target.Value

Sheets("Data").Select

For x = 1 To 10

If Cells(x, 1) = ItemNum Then
Desc = Cells(x, 2)
StdCost = Cells(x, 3)
Spec = Cells(x, 6)
End If

Next x

Sheets("Justification - working").Select

Cells(13, 4) = Desc
Cells(13, 6) = StdCost
Cells(13, 5) = Spec
End If

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Value not matching

Unqualified cell references in a worksheet module always refer to the sheet
containing the module. Does this version do what you want?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Integer
If Target.Address = "$C$13" Then
ItemNum = Target.Value
For x = 1 To 10
If Sheets("Data").Cells(x, 1) = ItemNum Then
Desc = Sheets("Data").Cells(x, 2)
StdCost = Sheets("Data").Cells(x, 3)
Spec = Sheets("Data").Cells(x, 6)
End If
Next x
Sheets("Justification - working").Cells(13, 4) = Desc
Sheets("Justification - working").Cells(13, 6) = StdCost
Sheets("Justification - working").Cells(13, 5) = Spec
End If
End Sub

Hope this helps,

Hutch

"Rpettis31" wrote:

I am running a loop to obtain values on a change event yet I can not seem to
obtain that value from the sheet I am looking at the values are returning a
blank?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim x As Integer

If Target.Address = "$C$13" Then
ItemNum = Target.Value

Sheets("Data").Select

For x = 1 To 10

If Cells(x, 1) = ItemNum Then
Desc = Cells(x, 2)
StdCost = Cells(x, 3)
Spec = Cells(x, 6)
End If

Next x

Sheets("Justification - working").Select

Cells(13, 4) = Desc
Cells(13, 6) = StdCost
Cells(13, 5) = Spec
End If

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Value not matching

Hi,

It's because it's worksheet code and your not qualifying the ranges with
which sheet that data values are located. Try this and note that we no
lionger select any sheets

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Long
If Target.Address = "$C$13" Then
ItemNum = Target.Value
For x = 1 To 10
If Sheets("Data").Cells(x, 1) = ItemNum Then
With Sheets("Data")
Desc = .Cells(x, 2)
StdCost = .Cells(x, 3)
Spec = .Cells(x, 6)
End With
Exit For
End If
Next x
With Sheets("Justification - working")
.Cells(13, 4) = Desc
.Cells(13, 6) = StdCost
.Cells(13, 5) = Spec
End With
End If
End Sub


Mike

"Rpettis31" wrote:

I am running a loop to obtain values on a change event yet I can not seem to
obtain that value from the sheet I am looking at the values are returning a
blank?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim x As Integer

If Target.Address = "$C$13" Then
ItemNum = Target.Value

Sheets("Data").Select

For x = 1 To 10

If Cells(x, 1) = ItemNum Then
Desc = Cells(x, 2)
StdCost = Cells(x, 3)
Spec = Cells(x, 6)
End If

Next x

Sheets("Justification - working").Select

Cells(13, 4) = Desc
Cells(13, 6) = StdCost
Cells(13, 5) = Spec
End If

End Sub

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
Help me to first row matching First date and last row matching lastrow [email protected] Excel Programming 3 January 21st 08 04:32 PM
Matching identical data using data only once in the matching proce Robert 1 Excel Discussion (Misc queries) 1 June 29th 07 04:22 PM
Help with Matching Text Fields - Then Moving the Matching Cells Side by Side [email protected] Excel Discussion (Misc queries) 2 June 11th 07 02:38 PM
Matching rows in 2 sheets and copying matching rows from sheet 1 t fbagirov Excel Programming 1 April 8th 07 03:44 PM
Matching data and linking it to the matching cell yvonne a via OfficeKB.com Links and Linking in Excel 0 July 13th 05 07:30 PM


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