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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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