If statement if cell is between 2 rows? [Beginner]

distiDoestoe

New Member
Joined
Dec 8, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm very new to VBA and I want to make an if statement is the selected cell is between two rows (between 6, 10 as an example).
Only I can't figure it out, I'm used to more different types of programming languages (Python, PHP, JavaScript) and with those I never really had issues but VBA I find very hard to learn / find a fix to problems.
I hope maybe someone can pinpoint me to the right direction. (And maybe some tips on where to learn more, like the W3schools for VBA...)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hello,

This code will show you a message box if the current cell is between row 6 & 10
You can change the show message box to whatever you want

VBA Code:
Sub findrow()
If ActiveCell.Row > 5 And ActiveCell.Row < 11 Then MsgBox "hello world"
End Sub
 
Upvote 0
Solution
Thank you, I didn't realise it could be this simple 😬😵‍💫😵‍💫😵
Hello,

This code will show you a message box if the current cell is between row 6 & 10
You can change the show message box to whatever you want

VBA Code:
Sub findrow()
If ActiveCell.Row > 5 And ActiveCell.Row < 11 Then MsgBox "hello world"
End Sub
 
Upvote 0
I didn't realise it could be this simple 😬😵‍💫😵‍💫😵
This is just for your information - You can also write it as below
VBA Code:
If ActiveCell.Row >= 6 And ActiveCell.Row <= 10 Then MsgBox "hello world"
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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