VBA - quick n easy for anyone that isn't as clueless as me: If "X" is found in range, do this"

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
801
Office Version
  1. 365
Platform
  1. Windows
Hi all, I have this which works when "X" is found in one column:

If Cells(ActiveCell.Row, "L").Value = "X" Then



But what about when X can be found in one of three columns?

If Range("R" & ActiveCell.Row & ":T" & ActiveCell.Row).Value = "X" Then


That returns an error.

Any ideas? I'd prefer to keep everything looking at ActiveCell.Row because I'm doing some nooby loops to get data. Cheers!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try
Code:
If Application.CountIf(Range("R" & ActiveCell.Row).Resize(, 3), "X") > 0 Then
 
Upvote 0
Try
Code:
If Application.CountIf(Range("R" & ActiveCell.Row).Resize(, 3), "X") > 0 Then

This works, and where I had to check across 5 rows I put in Resize(, 5) and that worked too, thanks!


I'm having another issue now where I have some variables defined to paste into another sheet, like this:

Code:
tno = Cells(ActiveCell.Row, "A").Value   
tnam = Cells(ActiveCell.Row, "B").Value
    cat = "AIP"
    cat2 = "Core"
    cat3 = "All"

And my full code looks like this:
Code:
M.Activate    Range("A3").Activate
    Do Until Cells(ActiveCell.Row, "A").Value = ""
    If Application.CountIf(Range("Y" & ActiveCell.Row).Resize(, 5), "X") > 0 Then
    
    
O.Activate
    Cells(ActiveCell.Row, "A").Value = tno
    Cells(ActiveCell.Row, "B").Value = tnam
    Cells(ActiveCell.Row, "D").Value = cat3
    
ActiveCell.Offset(1, 0).Activate
    
    
M.Activate
End If
ActiveCell.Offset(1, 0).Activate
Loop

So this is the one where it looks across range Y to AC of the active row. When it finds an X it puts to active row value of tno and tnam in memory (columns A and B)

These should be pasted onto sheet "O"

Instead, what's happening is it's only pasting the cat, cat2 and cat3 variables, in the correct place, but not putting in the tno or tnam.

Any ideas?

EDIT: I think I see, it's looking for the value in O sheet column A and B, when it should be looking at the value in the M sheet.

Bugger, how do I get around this?
 
Last edited:
Upvote 0
As this is now a completely different question you need to start a new thread
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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