Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Referencing a cell in VBA from a different worksheet

Hello,

I originally wrote this code for data that was on one sheet, but now I
want to look at data that is on Sheet 1 and if it fits the criteria
that I have listed on Sheet 2, then I will go through the j loop and
copy it. I don't know how to reference the cells in the 1st "if"
statement when they are on different sheets. Can someone please help
me?

Sub trial()
For k = 2 To 9
If Cells(k, 12) = Cells(17, 4) And Cells(k, 5) = Cells(17, 2)
And Cells(k, 5) <= Cells(17, 3) Then
For j = 1 To 26
Cells(k + 16, j) = Cells(k, j)
Next j
End If
Next k
End Sub



Thanks,
Stephen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Referencing a cell in VBA from a different worksheet

Maybe...

Option Explicit
Sub trial()

Dim Wks1 As Worksheet
Dim Wks2 As Worksheet

Set Wks1 = Worksheets("sheet1")
Set Wks2 = Worksheets("sheet2")

For k = 2 To 9
If Wks1.Cells(k, 12).Value = Wks2.Cells(17, 4).Value _
And Wks1.Cells(k, 5).Value = Wks2.Cells(17, 2).Value _
And Wks1.Cells(k, 5).Value <= Wks2.Cells(17, 3).Value Then
For j = 1 To 26
Wks1.Cells(k + 16, j).Value = Wks1.Cells(k, j).Value
Next j
End If
Next k

End Sub



Patel wrote:

Hello,

I originally wrote this code for data that was on one sheet, but now I
want to look at data that is on Sheet 1 and if it fits the criteria
that I have listed on Sheet 2, then I will go through the j loop and
copy it. I don't know how to reference the cells in the 1st "if"
statement when they are on different sheets. Can someone please help
me?

Sub trial()
For k = 2 To 9
If Cells(k, 12) = Cells(17, 4) And Cells(k, 5) = Cells(17, 2)
And Cells(k, 5) <= Cells(17, 3) Then
For j = 1 To 26
Cells(k + 16, j) = Cells(k, j)
Next j
End If
Next k
End Sub

Thanks,
Stephen


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Referencing a cell in VBA from a different worksheet

Which parts are Sheet1 and which Sheet2?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Patel" wrote in message
...
Hello,

I originally wrote this code for data that was on one sheet, but now I
want to look at data that is on Sheet 1 and if it fits the criteria
that I have listed on Sheet 2, then I will go through the j loop and
copy it. I don't know how to reference the cells in the 1st "if"
statement when they are on different sheets. Can someone please help
me?

Sub trial()
For k = 2 To 9
If Cells(k, 12) = Cells(17, 4) And Cells(k, 5) = Cells(17, 2)
And Cells(k, 5) <= Cells(17, 3) Then
For j = 1 To 26
Cells(k + 16, j) = Cells(k, j)
Next j
End If
Next k
End Sub



Thanks,
Stephen



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
referencing a cell in another worksheet Shannan Excel Discussion (Misc queries) 5 December 22nd 09 07:00 PM
Referencing a cell from another worksheet Shannan Excel Discussion (Misc queries) 3 November 20th 09 10:43 AM
Referencing a cell to another worksheet neostar77 Excel Discussion (Misc queries) 1 October 13th 08 09:23 AM
Referencing a worksheet name to a cell... QuietMan Excel Worksheet Functions 10 May 20th 08 02:40 PM
Referencing another worksheet via a cell [email protected] Excel Worksheet Functions 2 October 31st 06 07:22 PM


All times are GMT +1. The time now is 04:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"