Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Variable name question

I have some code as follows - how do I name the idate in the if statement?
In the case below I was trying to make sure that it would be 5/7/2009 on both
sides (A20 = 5/7/2009) so the if statement should work it does not read
("idate" & i) as = to idate7 - so how can I get the right side of the if
statement to come up with idate7, or idate8, etc? I will use the For Next
statement to get the i value (1 to 31) to change. Is it not the ("idate"& i)
that is wrong even trying ("idate" & "7") does not work but I don't know what
i am missing.

Set idate7 = ActiveSheet.Cells(20, 1)
Dim i As Integer
Let i = 7
If datecurrent = ("idate" & i) Then
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Variable name question

See VBA help for DateSerial(year, month, day)

you really should have Date in the IF stement if you don't use serial datte

if Range("A20") = date("5/7/2009") then


I fyou are trying to add 7 days to a date then use "+" not "&". The
aphersand connects strings together and doesn't add numbers

"5/7/2009" & 7 gives you

"5/7/20097"

You want

Date("5/7/20097") + 7




"JTWarthogs" wrote:

I have some code as follows - how do I name the idate in the if statement?
In the case below I was trying to make sure that it would be 5/7/2009 on both
sides (A20 = 5/7/2009) so the if statement should work it does not read
("idate" & i) as = to idate7 - so how can I get the right side of the if
statement to come up with idate7, or idate8, etc? I will use the For Next
statement to get the i value (1 to 31) to change. Is it not the ("idate"& i)
that is wrong even trying ("idate" & "7") does not work but I don't know what
i am missing.

Set idate7 = ActiveSheet.Cells(20, 1)
Dim i As Integer
Let i = 7
If datecurrent = ("idate" & i) Then

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Variable name question

You will need to use an array here if you want to loop through....


If this post helps click Yes
---------------
Jacob Skaria


"JTWarthogs" wrote:

I have some code as follows - how do I name the idate in the if statement?
In the case below I was trying to make sure that it would be 5/7/2009 on both
sides (A20 = 5/7/2009) so the if statement should work it does not read
("idate" & i) as = to idate7 - so how can I get the right side of the if
statement to come up with idate7, or idate8, etc? I will use the For Next
statement to get the i value (1 to 31) to change. Is it not the ("idate"& i)
that is wrong even trying ("idate" & "7") does not work but I don't know what
i am missing.

Set idate7 = ActiveSheet.Cells(20, 1)
Dim i As Integer
Let i = 7
If datecurrent = ("idate" & i) Then

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default Variable name question

I tried this and it seems to be working

Dim i As Integer
Let i = 1
For i = 1 To 30
If datecurrent = Worksheets("73-1 Data").Range("a" & i) Then
Worksheets("73").Range("b40").Copy Destination:=Worksheets("73-1
Data").Range("b" & i)
Worksheets("73").Range("b41").Copy Destination:=Worksheets("73-1
Data").Range("c" & i)
Worksheets("73").Range("b42").Copy Destination:=Worksheets("73-1
Data").Range("d" & i)
Worksheets("73").Range("b43").Copy Destination:=Worksheets("73-1
Data").Range("e" & i)
Worksheets("73").Range("b44").Copy Destination:=Worksheets("73-1
Data").Range("f" & i)
Worksheets("73").Range("b54").Copy Destination:=Worksheets("73-2
Data").Range("b" & i)
Worksheets("73").Range("b55").Copy Destination:=Worksheets("73-2
Data").Range("c" & i)
Worksheets("73").Range("b56").Copy Destination:=Worksheets("73-2
Data").Range("d" & i)
Worksheets("73").Range("b57").Copy Destination:=Worksheets("73-2
Data").Range("e" & i)
Worksheets("73").Range("b58").Copy Destination:=Worksheets("73-2
Data").Range("f" & i)
Worksheets("73").Range("b68").Copy Destination:=Worksheets("73-3
Data").Range("b" & i)
Worksheets("73").Range("b69").Copy Destination:=Worksheets("73-3
Data").Range("c" & i)
Worksheets("73").Range("b70").Copy Destination:=Worksheets("73-3
Data").Range("d" & i)
Worksheets("73").Range("b71").Copy Destination:=Worksheets("73-3
Data").Range("e" & i)
Worksheets("73").Range("b72").Copy Destination:=Worksheets("73-3
Data").Range("f" & i)
Worksheets("73").Range("b82").Copy Destination:=Worksheets("73-4
Data").Range("b" & i)
Worksheets("73").Range("b83").Copy Destination:=Worksheets("73-4
Data").Range("c" & i)
Worksheets("73").Range("b84").Copy Destination:=Worksheets("73-4
Data").Range("d" & i)
Worksheets("73").Range("b85").Copy Destination:=Worksheets("73-4
Data").Range("e" & i)
Worksheets("73").Range("b86").Copy Destination:=Worksheets("73-4
Data").Range("f" & i)
End If
Next i
End Sub

"joel" wrote:

See VBA help for DateSerial(year, month, day)

you really should have Date in the IF stement if you don't use serial datte

if Range("A20") = date("5/7/2009") then


I fyou are trying to add 7 days to a date then use "+" not "&". The
aphersand connects strings together and doesn't add numbers

"5/7/2009" & 7 gives you

"5/7/20097"

You want

Date("5/7/20097") + 7




"JTWarthogs" wrote:

I have some code as follows - how do I name the idate in the if statement?
In the case below I was trying to make sure that it would be 5/7/2009 on both
sides (A20 = 5/7/2009) so the if statement should work it does not read
("idate" & i) as = to idate7 - so how can I get the right side of the if
statement to come up with idate7, or idate8, etc? I will use the For Next
statement to get the i value (1 to 31) to change. Is it not the ("idate"& i)
that is wrong even trying ("idate" & "7") does not work but I don't know what
i am missing.

Set idate7 = ActiveSheet.Cells(20, 1)
Dim i As Integer
Let i = 7
If datecurrent = ("idate" & i) Then

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
two-variable data table question Judy Excel Discussion (Misc queries) 9 February 8th 09 09:12 AM
variable question peyman Excel Discussion (Misc queries) 3 October 16th 07 12:33 AM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
I Need VBA Assistance for global variable question Brent E Excel Discussion (Misc queries) 1 March 1st 05 08:46 PM


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