Vba if then concatenate

el_jm

New Member
Joined
Oct 21, 2014
Messages
21
Hello!
I have an issue with this VBA code, can someone have a look at this?
´ trying to get a concatenate (c4 & C8) string starting in B8 based on C8 value
(no big test, it has to be > 0) ...
the code works fine but instead of getting my (c4 & C8) in column, I am getting "error message" in front of cells > 0

Sub test_3()
'NOT OK
'limitS from l. 8 to 48
For i = 8 To 48
' if col 3 values greater than 0
If (Cells(i, 3)) > 0 Then
Cells(i, 2).Value = (C4 & c8)
'col 2 = my err mess
Cells(i, 2).Value = "error message"
End If
Next i
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Totally guessing here since the posted code doesn't seem to make much sense:

Code:
Sub test_3()

For i = 8 To 48
    If (Cells(i, 3).Value) > 0 Then
        Cells(i, 2).Value = Cells(4, 3).Value & Cells(i, 3).Value
    Else
        Cells(i, 2).Value = "error message"
    End If
Next i

End Sub

WBD
 
Upvote 0
OK thanks
Finally got it, modifying cells(i, 2).Value to ' 000 (c4 value I wanted to concatenate with C8).

Sub testMRxljm()

For i = 8 To 48
If (Cells(i, 3).Value) > 0 Then
Cells(i, 2).Value = "'000" & Cells(i, 3).Value
Else
Cells(i, 2).Value = "error message"
End If
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,222,907
Messages
6,168,963
Members
452,228
Latest member
just4jeffrey

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