View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default IF statements in Macros

Zak,

A bit short on details so just guessing this might get you goung in the
right direction.

Sub sonic()
Dim MyRange As Range
Set MyRange = Range("a1:a10")
For Each c In MyRange
If Left(c.Value, 3) = "GTS" Then
'do this
ElseIf Left(c.Value, 3) = "GTS" Then
'do that
Else
'do the other
End If
Next
End Sub

Mike

"Zak" wrote:

How do i put in IF statements in macros? i know what i want the macro to do
but cant seem to get the terminology correct, also can i put in numerous IF
statements within the same macro or do i need to create seperate modules?

an example: i want the macro to recognise that IF a cell begins with the
word GTS then it should replace it so it is only GTS. i also want to have IF
statments that say IF something = this then it should change to this. or IF
something = this then it should copy this or paste that.

i know what i want but dont know how to get it.

also, on a different note i am trying to create a macro that will build a
report based on a big spreadsheet. what is the best way to get around this as
at the moment i am just using the record macro option to record while i copy
and paste, hide etc cells to view just what is required for the report! then
format it to look nice, is there a better way to do this?

thanks in advance.