VBA If Then Statement

jtbrolly

New Member
Joined
Aug 22, 2011
Messages
42
Hey guys,

Not that good with coding, trying to make an if-then statement basically saying if it says something in column c, then write this with this formatting in column a. I've been looking all over for the exact coding and can't seem to find how to do it. Would really appreciate any help.

Thanks,
Jimmy
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,
I wouldnt use VBA code at all.

Place this formula in A1

=IF(C1="099","default","")

then place conditional formatting on coloum A that color changes it if it says default
 
Upvote 0
The thing is the sheet I'm working with isn't conducive to formulas. It's not the same sheet everyday, so rather than running a macro to write the formula, I'd rather just run a macro to write the words.
 
Upvote 0
may be this code
Code:
Sub Test()
Dim LR As Long, c As Range
LR = Range("c" & Rows.Count).End(xlUp).Row
For Each c In Range("c1:c" & LR)
    If c.Value <> "" Then
        c.Offset(, -2).Value = c.Value
    End If
Next c
End Sub
 
Upvote 0
Ah that's close. That one is writing in A, but it's copying the value from C. What would I change to have it write something different than just pulling the value from that column?

And what would I have to add so that if it isn't the number I'm looking for, leave it blank?
 
Upvote 0
I mean, for example, with this one: I want it to look in column C for o99, then if it sees that, in column A I want it to write Default and then color the cell Yellow. I think coloring the cell might be a conditional formatting function so I'll try to figure that out, but I'm having some trouble with the coding for this one.

There's a bunch of different things I want to write dependent on what's in column C, but I gave this specific example so try to see the code and understand it, so then I can apply it to the other cells as well.
 
Upvote 0
And what the code you gave was doing was copying the value over from C to A.

I also wanted it to not write anything if it's not the value I'm looking for.
 
Upvote 0
Code:
Sub Test()
Dim LR As Long, c As Range
LR = Range("c" & Rows.Count).End(xlUp).Row
For Each c In Range("c1:c" & LR)
    If c.Value <> "" Then
        c.Offset(, -2).Value = "default"
    End If
Next c
    Columns("A:A").Select
    With Selection
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""default"""
    .FormatConditions(1).Interior.ColorIndex = 3
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,741
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top