Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Setting string based on conditions

Option Explicit
Sub testme()

Dim myMsg As String
Dim myRng As Range
Dim myCell As Range

Set myRng = Worksheets("sheet9999").Range("a1:A7")

myMsg = ""
For Each myCell In myRng.Cells
If myCell.EntireRow.Hidden = True Then
'do nothing
Else
'I put a space between each value
myMsg = myMsg & " " & myCell.Value
End If
Next myCell

If myMsg = "" Then
'nothing found
Else
'get rid of the leading space
myMsg = Mid(myMsg, 2)
End If

MsgBox myMsg

End Sub


"brownti via OfficeKB.com" wrote:

Does anyone have some example code that will set values in a string based on
a condition? For example if row 1 is hidden go on to row 2. If Row 2 is not
hidden set MSGBODY = Range("A2"). If Row 3 is not hidden set MSGBODY = (All
previous conditions and also) Range("A3"). And so on....

I cant figure out how to keep one condition will adding another condition to
the string. What i have is seven rows, some are hidden and some are not.
Depending on if the row is hidden or not i want to put a value from that row
into a string and then use that string in an email message using .Body. Any
ideas?

--
Message posted via http://www.officekb.com


--

Dave Peterson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 527
Default Setting string based on conditions

God I don't read very well at times - Good one Dave


Peter

"Dave Peterson" wrote:

Option Explicit
Sub testme()

Dim myMsg As String
Dim myRng As Range
Dim myCell As Range

Set myRng = Worksheets("sheet9999").Range("a1:A7")

myMsg = ""
For Each myCell In myRng.Cells
If myCell.EntireRow.Hidden = True Then
'do nothing
Else
'I put a space between each value
myMsg = myMsg & " " & myCell.Value
End If
Next myCell

If myMsg = "" Then
'nothing found
Else
'get rid of the leading space
myMsg = Mid(myMsg, 2)
End If

MsgBox myMsg

End Sub


"brownti via OfficeKB.com" wrote:

Does anyone have some example code that will set values in a string based on
a condition? For example if row 1 is hidden go on to row 2. If Row 2 is not
hidden set MSGBODY = Range("A2"). If Row 3 is not hidden set MSGBODY = (All
previous conditions and also) Range("A3"). And so on....

I cant figure out how to keep one condition will adding another condition to
the string. What i have is seven rows, some are hidden and some are not.
Depending on if the row is hidden or not i want to put a value from that row
into a string and then use that string in an email message using .Body. Any
ideas?

--
Message posted via http://www.officekb.com


--

Dave Peterson

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
Sort by setting two conditions Waveney Johnny Excel Worksheet Functions 2 September 17th 09 07:13 PM
shade cells based on conditions - i have more than 3 conditions Mo2 Excel Worksheet Functions 3 March 30th 07 07:19 AM
Need help setting the worksheet header/Footer margins based on string height? Doug Excel Programming 3 August 21st 06 05:08 PM
Need help setting the worksheet header/Footer margins based on string height? Doug Excel Discussion (Misc queries) 0 August 20th 06 02:05 AM
setting two conditions for countif Danny J Excel Worksheet Functions 5 December 6th 04 11:49 PM


All times are GMT +1. The time now is 09:13 PM.

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"