VBA question

seannewtoexcel

New Member
Joined
Jul 28, 2011
Messages
8
Hi, I'm new to VBA and posting on forums!! Trying to learn VBA and I have a few stupid questions which I hope someone can help me with, In relation to the below code for VBA:


If ActiveCell.Address <> "$A$1" Then
Dim tempstr As String
tempstr = ActiveCell.Address
If (Mid(tempstr, InStrRev(tempstr, "$") + 1, Len(tempstr)) > 1) And (Mid(tempstr, InStrRev(tempstr, "$") + 1, Len(tempstr)) < 42) Then
MsgBox ("Computer Says No")
Exit Sub


The ActiveCell.Address is (cell) $CP$40, I'm just curious is tempstr now $CP$40 and therefore Mid(tempstr, InStrRev(tempstr, "$") + 1, Len(tempstr)) would be Mid($CP$40,4,6), which would have to be = 0?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Welcome to the board...

No, it would be 40..

It's basically a VERY long roundabout way of getting the Row # of the active cell.

It is much easier to get the row # of the activecell with this..
ActiveCell.Row

So the If statement could be this instead

If ActiveCell.Row > 1 And ActiveCell.Row < 42 Then


Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

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