Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Set range based on cell contents - help required

Hello all

My column contains dates (in order but some dates are missing)
I want to specify a range in VBA based on two cells elsewhere on th
sheet.
I know to write N196 for the start date and < N197 for the end date t
avoid problems if the actual date is not in the list. However how woul
I fit this into my code.

Code below

Sub MyBetweenDates()
Dim x As Long
Dim lLastrow As Long
Dim wsNew As Worksheet, wsCurr As Worksheet
Dim rCell As Range
Dim vContents As Variant

Set wsCurr = Sheets("Data")
Set wsNew = Worksheets.Add
wsNew.Name = "Dates"
lLastrow = wsCurr.Range("A65536").End(xlUp).Row

x = 1

For Each rCell In wsCurr.Range("C2:C" & lLastrow)

'the next line is the problemxxxxxxxxxxxxxxxxxxxxxxxxxx

If rCell.Value Range("N196").value and<"Range"("N197").value Then

'the above line is the problemxxxxxxxxxxxxxxxxxxxxxxxxx

vContents = wsCurr.Range(rCell.Offset(0, -2), rCell.Offset(0
12)).Value
wsNew.Range("A" & x & ":O" & x).Value = vContents
x = x + 1
End If
Next rCell


End Sub


Can anyone help?

TIA
Kenny

using combinations of Win2000, Win Me, Office 97 and Office 200

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Set range based on cell contents - help required

Hi N E,

Change:

If rCell.Value Range("N196").value and<"Range"("N197").value Then

to:

If rCell.Value Range("N196").value And Rcell < Range"("N197").value Then

---
Regards,
Norman




"N E Body " wrote in message
...
Hello all

My column contains dates (in order but some dates are missing)
I want to specify a range in VBA based on two cells elsewhere on the
sheet.
I know to write N196 for the start date and < N197 for the end date to
avoid problems if the actual date is not in the list. However how would
I fit this into my code.

Code below

Sub MyBetweenDates()
Dim x As Long
Dim lLastrow As Long
Dim wsNew As Worksheet, wsCurr As Worksheet
Dim rCell As Range
Dim vContents As Variant

Set wsCurr = Sheets("Data")
Set wsNew = Worksheets.Add
wsNew.Name = "Dates"
lLastrow = wsCurr.Range("A65536").End(xlUp).Row

x = 1

For Each rCell In wsCurr.Range("C2:C" & lLastrow)

'the next line is the problemxxxxxxxxxxxxxxxxxxxxxxxxxx

If rCell.Value Range("N196").value and<"Range"("N197").value Then

'the above line is the problemxxxxxxxxxxxxxxxxxxxxxxxxx

vContents = wsCurr.Range(rCell.Offset(0, -2), rCell.Offset(0,
12)).Value
wsNew.Range("A" & x & ":O" & x).Value = vContents
x = x + 1
End If
Next rCell


End Sub


Can anyone help?

TIA
Kenny

using combinations of Win2000, Win Me, Office 97 and Office 2000


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Set range based on cell contents - help required

If rCell.Value = wsCurr.Range("N196").value and _
rCell.Value <= wsCurr.Range("N197").value Then

should work with your code.

--
Regards,
Tom Ogilvy

"N E Body " wrote in message
...
Hello all

My column contains dates (in order but some dates are missing)
I want to specify a range in VBA based on two cells elsewhere on the
sheet.
I know to write N196 for the start date and < N197 for the end date to
avoid problems if the actual date is not in the list. However how would
I fit this into my code.

Code below

Sub MyBetweenDates()
Dim x As Long
Dim lLastrow As Long
Dim wsNew As Worksheet, wsCurr As Worksheet
Dim rCell As Range
Dim vContents As Variant

Set wsCurr = Sheets("Data")
Set wsNew = Worksheets.Add
wsNew.Name = "Dates"
lLastrow = wsCurr.Range("A65536").End(xlUp).Row

x = 1

For Each rCell In wsCurr.Range("C2:C" & lLastrow)

'the next line is the problemxxxxxxxxxxxxxxxxxxxxxxxxxx

If rCell.Value Range("N196").value and<"Range"("N197").value Then

'the above line is the problemxxxxxxxxxxxxxxxxxxxxxxxxx

vContents = wsCurr.Range(rCell.Offset(0, -2), rCell.Offset(0,
12)).Value
wsNew.Range("A" & x & ":O" & x).Value = vContents
x = x + 1
End If
Next rCell


End Sub


Can anyone help?

TIA
Kenny

using combinations of Win2000, Win Me, Office 97 and Office 2000


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Set range based on cell contents - help required

Hi N E,

That Should have been:

If rCell.Value Range("N196").Value And rCell.Value< Range"("N197").Value
Then

---
Regards,
norman

"Norman Jones" wrote in message
...
Hi N E,

Change:

If rCell.Value Range("N196").value and<"Range"("N197").value Then

to:

If rCell.Value Range("N196").value And Rcell < Range"("N197").value Then

---
Regards,
Norman




"N E Body " wrote in message
...
Hello all

My column contains dates (in order but some dates are missing)
I want to specify a range in VBA based on two cells elsewhere on the
sheet.
I know to write N196 for the start date and < N197 for the end date to
avoid problems if the actual date is not in the list. However how would
I fit this into my code.

Code below

Sub MyBetweenDates()
Dim x As Long
Dim lLastrow As Long
Dim wsNew As Worksheet, wsCurr As Worksheet
Dim rCell As Range
Dim vContents As Variant

Set wsCurr = Sheets("Data")
Set wsNew = Worksheets.Add
wsNew.Name = "Dates"
lLastrow = wsCurr.Range("A65536").End(xlUp).Row

x = 1

For Each rCell In wsCurr.Range("C2:C" & lLastrow)

'the next line is the problemxxxxxxxxxxxxxxxxxxxxxxxxxx

If rCell.Value Range("N196").value and<"Range"("N197").value Then

'the above line is the problemxxxxxxxxxxxxxxxxxxxxxxxxx

vContents = wsCurr.Range(rCell.Offset(0, -2), rCell.Offset(0,
12)).Value
wsNew.Range("A" & x & ":O" & x).Value = vContents
x = x + 1
End If
Next rCell


End Sub


Can anyone help?

TIA
Kenny

using combinations of Win2000, Win Me, Office 97 and Office 2000


---
Message posted from http://www.ExcelForum.com/





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Set range based on cell contents - help required

Many thanks

That did the trick

Kenn

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Set range based on cell contents - help required

Range("N196") and Range("N197") are on the new sheet you just added where
you have added no values? Or is the code in the sheet module of the sheet
with the Dates?

--
Regards,
Tom Ogilvy

"N E Body " wrote in message
...
Many thanks

That did the trick

Kenny


---
Message posted from http://www.ExcelForum.com/



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
Hyperlink to Named Range Based On Cell Contents TKS_Mark Excel Worksheet Functions 1 January 9th 08 04:14 PM
Return entries from one named range based on the contents of another Sam Crump Excel Worksheet Functions 1 March 6th 06 04:00 PM
Reference Data Range based on cell contents PCLIVE Charts and Charting in Excel 0 February 27th 06 03:01 PM
Formatting a range based on contents of column/row heading Chris Crowe Excel Programming 0 August 20th 03 06:15 PM
Formatting a range based on contents of column/row heading Chris Excel Programming 1 August 20th 03 05:06 PM


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