VBA - If statement - Range

Shukis7

New Member
Joined
Dec 14, 2021
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi,

This is my previous thread which got resolved:

"I'm trying to use the Textjoin function in VBA.

I know how to do it for the first row, but I'm having issues when I want it to apply for the whole column.

For example, I want it to start at AH2 and the formula on the cell should be =TEXTJOIN("-",TRUE,I2,AE2,AF2,AG2).
For AH3 the formula should be =TEXTJOIN("-",TRUE,I3,AE3,AF3,AG3) and the same for AH4...
I know it should be something for i =1 in the range ... but I can't figure it out. (for each cell in range)

Any help would be really appreciated.

Thanks!"

The answer to this is the following:

"
Sub Shukis7()
Dim lr As Long
lr = Cells.Find("*", , xlFormulas, , 1, 2).Row
With Range("AH2:AH" & lr)
.FormulaR1C1 = "=TEXTJOIN("" - "",TRUE,RC9,RC31,RC32,RC33)"
.Value2 = .Value2
End With
End Sub
"

This worked perfectly, but now instead of textjoin I want to use the following formula: IF(COUNTIF($AH$2:AH2,AH2)>1,"Duplicate","Original")
The concept is the same, but now I am using only the column AH (RC34). I've tried modifying the previous formula, but it doesn't seem to work.

Any help would be really appreciated! Thank you!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try it like this

VBA Code:
Sub Shukis7()
Dim lr As Long
lr = Cells.Find("*", , xlFormulas, , 1, 2).Row
With Range("Ag2:Ag" & lr)
.Formula = "= IF(COUNTIF($AH$2:AH2,AH2)>1,""Duplicate"",""Original"")"
.Value2 = .Value2
End With
End Sub
 
Last edited:
Upvote 0
Solution
I've already tried that, it doesn't work. It's giving me Runtime Error 1004 "Application-defined or Object-defined error". Any other ideas? Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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