Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 270
Default If then Else in macro

I am trying in vain to incorporate an If Then Else into a macro; the basis
is as follows

Sheet Name = 'Search'

If -Cells in the ranges (B5:F5) AND (B8:F8) AND (C8) AND (F9) = ""
Then
Do this
Else
Do that
End If

The bit between 'If' and 'Then' eludes me. Any offers?

Sandy


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,355
Default If then Else in macro

What do you want to do? Let's say you want to change the values of those
cells.

Cells(RowNum, ColNum).value = 10 '<~~~changes the value in the cell at the
location given
Range("C8").value = 10 '<~~changes the value in C8 to 10

It's tough to know how to answer without a more specific question.

"Sandy" wrote:

I am trying in vain to incorporate an If Then Else into a macro; the basis
is as follows

Sheet Name = 'Search'

If -Cells in the ranges (B5:F5) AND (B8:F8) AND (C8) AND (F9) = ""
Then
Do this
Else
Do that
End If

The bit between 'If' and 'Then' eludes me. Any offers?

Sandy



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,624
Default If then Else in macro

One way:

With Sheets("Search").Range("B5:F5,B8:F8,F9")
If Application.CountA(.Cells) < .Count Then
'Do This
Else
'Do That
End If
End With




In article ,
"Sandy" wrote:

I am trying in vain to incorporate an If Then Else into a macro; the basis
is as follows

Sheet Name = 'Search'

If -Cells in the ranges (B5:F5) AND (B8:F8) AND (C8) AND (F9) = ""
Then
Do this
Else
Do that
End If

The bit between 'If' and 'Then' eludes me. Any offers?

Sandy

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default If then Else in macro

Are you checking to see if the cells are empty?

Dim myRng As Range
Set myRng = Worksheets("Sheet1").Range("b5:f5,B8:f8,F9")
If Application.CountA(myRng) = 0 Then
'all empty
Else
'not all empty
End If

=counta() will count any cell that has a formula that evaluates to "".

And C8 is part of B8:F8, so it doesn't need to be checked twice.

Sandy wrote:

I am trying in vain to incorporate an If Then Else into a macro; the basis
is as follows

Sheet Name = 'Search'

If -Cells in the ranges (B5:F5) AND (B8:F8) AND (C8) AND (F9) = ""
Then
Do this
Else
Do that
End If

The bit between 'If' and 'Then' eludes me. Any offers?

Sandy


--

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
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
using a cell value to control a counter inside a macro and displaying macro value ocset Excel Worksheet Functions 1 September 10th 06 05:32 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM


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