Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default code for a formula

HI

Can anybody help me write a macro code for this?

For i = 5 To Cells(39, 2).Value
Cells(3, i).Value = MID(TEXT(B37+k ,"dddd"),1,3)
k = k + 1
Next i


My problem is that i am not able to write a code for formula.


thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default code for a formula

If I read you right then try this for the Text function

Cells(3, i).Value = Mid(Application.WorksheetFunction.Text(B37 + k, "dddd"),
1, 3)


--

Regards,
Nigel




"hoysala" wrote in message
...
HI

Can anybody help me write a macro code for this?

For i = 5 To Cells(39, 2).Value
Cells(3, i).Value = MID(TEXT(B37+k ,"dddd"),1,3)
k = k + 1
Next i


My problem is that i am not able to write a code for formula.


thank you


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default code for a formula

Okay, I have a few comments. First, you can't refer to a cell value by just
giving its address... in VBA, B37 is assumed to be a variable name, not a
cell reference. So the best way to refer to B37+k in a loop is by using
Cells(37+k,"B"). Next, the VB function you want to use in place of TEXT is
Format. From the looks of your formula, it looks like B37+k will contain a
date (I assume that from you use of the "dddd" parameter that you tried to
use) and that you are trying to assign the abbreviation for the day name to
Cells(3,i). This would do what you want...

Cells(3, i).Value = Mid(Format(Cells(37 + k, "B") ,"dddd"),1,3)

However, you don't need to use the Mid function (either in VB or at the
worksheet level as TEXT uses the same format pattern parameter) in order to
get the abbreviation for the day name... just use 3 d's instead of 4 of
them. This will also do what you want...

Cells(3, i).Value = Format(Cells(37 + k, "B"), "ddd")

And, just so you are aware, you could also to what you want this way...

Cells(3, i).Value = WeekdayName(Weekday(Cells(37 + k, "B").Value), True)

Yes, I know its longer... just wanted to show you another way using date
specific functions. Speaking of date specific functions, there is still yet
another way to do what you want....

Cells(3, i).Value = WeekdayName(DatePart("w", Cells(37+k, "B").Value),True)

Me personally... I would use the second method above, namely....

Cells(3, i).Value = Format(Cells(37 + k, "B"), "ddd")

Rick


"hoysala" wrote in message
...
HI

Can anybody help me write a macro code for this?

For i = 5 To Cells(39, 2).Value
Cells(3, i).Value = MID(TEXT(B37+k ,"dddd"),1,3)
k = k + 1
Next i


My problem is that i am not able to write a code for formula.


thank you


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
Using formula in code Alan M Excel Programming 1 August 17th 07 02:09 AM
Using formula in code Halim Excel Programming 0 August 17th 07 01:45 AM
Formula in code jln via OfficeKB.com Excel Programming 2 July 13th 07 03:02 PM
Have a Formula I want to put in to some Code Q John Excel Programming 2 June 5th 04 04:39 PM
SUM Formula using code Sony[_2_] Excel Programming 1 August 27th 03 09:34 AM


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