Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Basics

Status
Not open for further replies.

SilverFreak

Programmer
Aug 28, 2003
15
0
0
GB
I need to write a macro to work by tomorrow morning, so I'd appreciate any help.

I'm trying to use an IF....ELSE statement but I can't seem to get it to work.

I want the macro to check if a cell, say (A2), has a "v" in it. If it doesn't then I want it to show a default value. If the cell has a "v" in it then I want it to copy cell (A15) and paste it into (A2).

Then I want the whole operation to move to Column 3. eg, Cell (B2) and (B15).

I tried to find a thread with this sort of thing on it, but I haven't got much time!!!

Cheers

SilverFreak
 
SilverFreak,
Code:
for col = 1 to 2
  with cells(2, col)
    if .value like "*v*" then
      .value = defaultvalue
    else
      .value = cells(15, col).value
    end if
  end with
next


Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
If I understand the requirement, like this.

Code:
Sub Mysub()

LastCol = 10
For MyCol = 1 To LastCol
    If Cells(2, MyCol) = "v" Then
        Cells(2, MyCol) = Cells(15, MyCol)
    End If
Next MyCol

End Sub
 
Hi,

That seems to work fine, but I forgot to mention that I have a range of cells to scan whether they have "v" in. And then move along one column, and then another column. etc

Thanks

 
...I have a range of cells to scan...[/b]
Please be more specific. My crystal ball is foggy.

Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Sorry, From Cell (A9) to (A13), Cell (B9) to (B13) etc.
 
Code:
for col = 1 to 2
  for row = 9 to 13
    with cells(row, col)
      if .value like "*v*" then
        .value = defaultvalue
      else
        .value = cells(15, col).value
      end if
    end with
  next
next

Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Hi,
Thanks to you both. It works exactly how I needed it to.

Cheers

SilverFreak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top