Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default variable question

want to use a dropdown with the days of the week. if i hard code this it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?
--


Gary



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default variable question

Can't be done. VBA is an compiled language (as opposed to an interpreted
language like vbScript), which has the consequence that the code has no
awareness of its own variable and constant names. That is, you can construct
"vbMonday" as a string; but there's no way to use that string to refer to a
variable or constant with that name.

If you need to convert "Monday" to vbMonday, you need to use some kind of
look up structure, case statement, or equivalent.



"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
want to use a dropdown with the days of the week. if i hard code this it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?
--


Gary





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default variable question

On Tue, 15 Nov 2005 21:11:04 -0500, "Gary Keramidas" <GKeramidasATmsn.com
wrote:

want to use a dropdown with the days of the week. if i hard code this it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?


vbMonday is a constant equal to 2 (vbSunday=1 and so forth).

Since you have the spelled out day of the week in cell, it's just a matter of
translating it to the appropriate weekday number. So one way:

---------------------------------------------
weekdays = Array("Sunday", "Monday", "Tuesday", "Wednesday", _
"Thursday", "Friday", "Saturday")
WD = Application.WorksheetFunction.Match(cell, weekdays, 0)
---------------------------------------------
Then you can use:

If WD = vbMonday Then

------------------------


--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default variable question

ok thanks, i think i'll resort to the if else thing

--


Gary


"Ron Rosenfeld" wrote in message
...
On Tue, 15 Nov 2005 21:11:04 -0500, "Gary Keramidas" <GKeramidasATmsn.com
wrote:

want to use a dropdown with the days of the week. if i hard code this it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?


vbMonday is a constant equal to 2 (vbSunday=1 and so forth).

Since you have the spelled out day of the week in cell, it's just a matter
of
translating it to the appropriate weekday number. So one way:

---------------------------------------------
weekdays = Array("Sunday", "Monday", "Tuesday", "Wednesday", _
"Thursday", "Friday", "Saturday")
WD = Application.WorksheetFunction.Match(cell, weekdays, 0)
---------------------------------------------
Then you can use:

If WD = vbMonday Then

------------------------


--ron



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default variable question

weekday("Monday") = vbMonday

gives me a type mismatch error. If that isn't what you meant, then
clarify.

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
want to use a dropdown with the days of the week. if i hard code this it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?
--


Gary







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default variable question

there is a date in column A. if i use "If weekday(cell.value) = vbMonday
Then" the code works fine. so i have a dropdown in A2 with Monday thru
Saturday listed.
i wanted to use
"If cell.value = "vb" & Range.("A2").value. Then"
or some form of that with a variable but it didn't work.

i just used if/elseif statements.
--


Gary


"Tom Ogilvy" wrote in message
...
weekday("Monday") = vbMonday

gives me a type mismatch error. If that isn't what you meant, then
clarify.

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
want to use a dropdown with the days of the week. if i hard code this it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?
--


Gary







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default variable question

vbSunday is 1 and vbSaturday is 7, so you can check against the numbers 1 to
7.

If that doesn't answer it, you would have to be much more specific about
what you are trying to check/how/when/why/what decision you ar e making,
because frankly,
"If cell.value = "vb" & Range.("A2").value. Then"

doesn't make much sense.
--
Regards,
Tom Ogilvy

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
there is a date in column A. if i use "If weekday(cell.value) = vbMonday
Then" the code works fine. so i have a dropdown in A2 with Monday thru
Saturday listed.
i wanted to use
"If cell.value = "vb" & Range.("A2").value. Then"
or some form of that with a variable but it didn't work.

i just used if/elseif statements.
--


Gary


"Tom Ogilvy" wrote in message
...
weekday("Monday") = vbMonday

gives me a type mismatch error. If that isn't what you meant, then
clarify.

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
want to use a dropdown with the days of the week. if i hard code this

it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?
--


Gary









  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default variable question

hopefully this will explain what i was trying to do.
here's the code snippet:

'A2 is the dropdown range
If UCase(Worksheets("report").Range("A2")) = "MONDAY" Then
wday = 2
ElseIf UCase(Worksheets("report").Range("A2")) = "TUESDAY" Then
wday = 3
ElseIf UCase(Worksheets("report").Range("A2")) = "WEDNESDAY" Then
wday = 4
ElseIf UCase(Worksheets("report").Range("A2")) = "THURSDAY" Then
wday = 5
ElseIf UCase(Worksheets("report").Range("A2")) = "FRIDAY" Then
wday = 6
Else
wday = 7
End If


With Worksheets(i) ' there are 12 of them, didn't post this loop
Set rng = .Range("A4:a34")
For Each cell In rng.Cells
If Not IsDate(cell.Value) Then
lastrow = lastrow - 1
End If
If Weekday(cell.Value) = wday Then ' * see below
Worksheets("report").Range("B" & lastrow + 1) = cell.Value
Worksheets("report").Range("C" & lastrow + 1) = cell.Offset(0, 1).Value
Worksheets("report").Range("D" & lastrow + 1) = cell.Offset(0, 4).Value
Worksheets("report").Range("E" & lastrow + 1) = cell.Offset(0, 7).Value
Worksheets("report").Range("F" & lastrow + 1) = cell.Offset(0, 10).Value
Worksheets("report").Range("G" & lastrow + 1) = cell.Offset(0, 13).Value
'Range("H" & lastrow + 1).Formula = "=sum(c" & lastrow + 1 & ":G" & lastrow
+ 1 & ")"
End If

*this is where i was trying to concatenate the "vb" and the value of A2
(vbMonday for example, if A2 contained Monday)
i was trying to use,
If Weekday(cell.Value) = "vb" & Range("A2") Then
but i used the if statements instead
--


Gary


"Tom Ogilvy" wrote in message
...
vbSunday is 1 and vbSaturday is 7, so you can check against the numbers 1
to
7.

If that doesn't answer it, you would have to be much more specific about
what you are trying to check/how/when/why/what decision you ar e making,
because frankly,
"If cell.value = "vb" & Range.("A2").value. Then"

doesn't make much sense.
--
Regards,
Tom Ogilvy

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
there is a date in column A. if i use "If weekday(cell.value) = vbMonday
Then" the code works fine. so i have a dropdown in A2 with Monday thru
Saturday listed.
i wanted to use
"If cell.value = "vb" & Range.("A2").value. Then"
or some form of that with a variable but it didn't work.

i just used if/elseif statements.
--


Gary


"Tom Ogilvy" wrote in message
...
weekday("Monday") = vbMonday

gives me a type mismatch error. If that isn't what you meant, then
clarify.

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
want to use a dropdown with the days of the week. if i hard code this

it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?
--


Gary











  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default variable question

Pick a date you know is Monday (ex: Dec 6, 2004)

Dim dt as Date, s as String
set dt = DateSerial(2004,12,6)
s = Ucase(Worksheets("Report").Range("A2').Text
for i = 1 to 5
if s = Ucase(Format(dt+i-1,"dddd")) then
wday = i + 1
exit for
end if
Next

If your dropdown box was populated from a range of cells that containd
Monday - Friday (assume range is named weekdays)

With Worksheets("Report")
res = Application.Match(.Range("A2").Text,Range("Weekday s"),0)
if not iserror(res) then
wday = res + 1
end if
End with



--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
hopefully this will explain what i was trying to do.
here's the code snippet:

'A2 is the dropdown range
If UCase(Worksheets("report").Range("A2")) = "MONDAY" Then
wday = 2
ElseIf UCase(Worksheets("report").Range("A2")) = "TUESDAY" Then
wday = 3
ElseIf UCase(Worksheets("report").Range("A2")) = "WEDNESDAY" Then
wday = 4
ElseIf UCase(Worksheets("report").Range("A2")) = "THURSDAY" Then
wday = 5
ElseIf UCase(Worksheets("report").Range("A2")) = "FRIDAY" Then
wday = 6
Else
wday = 7
End If


With Worksheets(i) ' there are 12 of them, didn't post this loop
Set rng = .Range("A4:a34")
For Each cell In rng.Cells
If Not IsDate(cell.Value) Then
lastrow = lastrow - 1
End If
If Weekday(cell.Value) = wday Then ' * see below
Worksheets("report").Range("B" & lastrow + 1) = cell.Value
Worksheets("report").Range("C" & lastrow + 1) = cell.Offset(0, 1).Value
Worksheets("report").Range("D" & lastrow + 1) = cell.Offset(0, 4).Value
Worksheets("report").Range("E" & lastrow + 1) = cell.Offset(0, 7).Value
Worksheets("report").Range("F" & lastrow + 1) = cell.Offset(0, 10).Value
Worksheets("report").Range("G" & lastrow + 1) = cell.Offset(0, 13).Value
'Range("H" & lastrow + 1).Formula = "=sum(c" & lastrow + 1 & ":G" &

lastrow
+ 1 & ")"
End If

*this is where i was trying to concatenate the "vb" and the value of A2
(vbMonday for example, if A2 contained Monday)
i was trying to use,
If Weekday(cell.Value) = "vb" & Range("A2") Then
but i used the if statements instead
--


Gary


"Tom Ogilvy" wrote in message
...
vbSunday is 1 and vbSaturday is 7, so you can check against the numbers

1
to
7.

If that doesn't answer it, you would have to be much more specific about
what you are trying to check/how/when/why/what decision you ar e making,
because frankly,
"If cell.value = "vb" & Range.("A2").value. Then"

doesn't make much sense.
--
Regards,
Tom Ogilvy

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
there is a date in column A. if i use "If weekday(cell.value) =

vbMonday
Then" the code works fine. so i have a dropdown in A2 with Monday thru
Saturday listed.
i wanted to use
"If cell.value = "vb" & Range.("A2").value. Then"
or some form of that with a variable but it didn't work.

i just used if/elseif statements.
--


Gary


"Tom Ogilvy" wrote in message
...
weekday("Monday") = vbMonday

gives me a type mismatch error. If that isn't what you meant, then
clarify.

--
Regards,
Tom Ogilvy


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
want to use a dropdown with the days of the week. if i hard code

this
it
works

If Weekday(cell.Value) = vbMonday Then

but if i try to concatenate "vb" and the value of the dropdown in A2
(Monday"), it doesn't.

what do i need to do to get it to work?
--


Gary













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
Variable name question JTWarthogs Excel Discussion (Misc queries) 3 May 7th 09 02:22 PM
variable question peyman Excel Discussion (Misc queries) 3 October 16th 07 12:33 AM
variable question Gary Keramidas[_2_] Excel Programming 5 September 2nd 05 08:30 AM
Pass Variable Question SyrHoop Excel Programming 2 November 10th 04 05:15 PM
variable Question Shane Excel Programming 2 July 5th 04 08:30 AM


All times are GMT +1. The time now is 01:47 PM.

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"