VBA If And Then Else Not Working

Little_Ghost

New Member
Joined
Dec 13, 2010
Messages
48
Hi Guys,

I have this VBA code which I thought was working, but it isn't. At least, not completely.
I've spend hours trying to figure out what is wrong but I can't figure it out.
Maybe someone here can find it?

This is the code:
Code:
Sub InsertRowAndCopyFormulas()
    Dim dest As Range
    Application.ScreenUpdating = False
    If ActiveCell.Column >= F And ActiveCell.Row <= 10 Then
           
    MsgBox "Please click OK and select" _
     & vbCrLf & "a row after row 11 and" _
     & vbCrLf & "before column E."
    Else


    ActiveCell.EntireRow.Insert
    Set dest = ActiveCell.Worksheet.Cells(ActiveCell.Row, 1)
    dest.Offset(1).Resize(, dest.Worksheet.UsedRange.Columns.Count).Copy dest


    End If
    Application.ScreenUpdating = True


End Sub
It seems to neglect the column value: when I'm in F11 I can add a row, which I shouldn't be able to.

I hope someone can help me.

Kind regards,

Little Ghost
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Just a guess

Code:
If ActiveCell.Column >= F And ActiveCell.Row <= 10 Then

Should that be "F" instead of F ?
 
Upvote 0
> operations work on NUMBERS not Text Strings.

Try
If ActiveCell.Column >= 6 And ActiveCell.Row <= 10 Then

(F is the 6th column)
 
Upvote 0
Column returns a number, so:

Code:
If ActiveCell.Column >= 6 And ActiveCell.Row <= 10 Then
 
Upvote 0
I think you want Or not And in that line.
 
Upvote 0
I think you want Or not And in that line.

Thought about that and tested it but didn't work... then again... that was with F, not 6 ... let me try...

**edit**
That seems to do the trick!
OR instead of AND , and the "Number of column" instead of "letter of column"

THANKS!!!!!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,222,903
Messages
6,168,939
Members
452,227
Latest member
sam1121

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