End IF Without Block IF Error

pjmsimmons

Board Regular
Joined
Dec 13, 2011
Messages
80
Hi All,
I am trying to create a reasonably complicated macro within an excel workbook. I might end up coming to the forum several times for help but this is my first question on the first part of what I'm trying to do.

I have a worksheet called 'blood' in which I select various cells in column B. For each x in my selection I wish to copy the cell content to a separate worksheet called 'Blood Report' if X.offset (0,9) = "1". The contents of the cell will be pasted into column B of the 'Blood Report ' worksheet starting at cell B65.

thus far I have

Code:
Sub Test_Report()


Dim x As Range, lstrw As Long


lstrw = Sheets("Blood Report").Cells(Rows.Count, "B65").End(xlUp).Row


Application.ScreenUpdating = False


With Sheets("Blood")


For Each x In Selection


If x.Offset(0, 9) = "1" Then


With Sheets("Blood Report").Range("B65:B" & lstrw) = x




End If


Next x




End Sub
but I keep getting an error End IF Without Block If.

any help available?

regards,

Paul
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Thanks Tim. I have added two End With statements but seem to have generated another error on the 'lstrw = ' line. Sorry to ask but do you have any further help?



Code:
Sub Test_Report()


Dim x As Range, lstrw As Long


lstrw = Sheets("Blood Report").Cells(Rows.Count, "B").End(xlUp).Row


Application.ScreenUpdating = False


With Sheets("Blood")


For Each x In Selection


If x.Offset(0, 9) = "1" Then


With Sheets("Blood Report").Range("B65:B" & lstrw) = x


End With


End If


Next x


End With


End Sub
No error is generated but neither is it copying the data from the 'Blood' Sheet to the 'Blood Report' sheet.
 
Upvote 0
you can ignore this statement 'No error is generated but neither is it copying the data from the 'Blood' Sheet to the 'Blood Report' sheet.'
 
Upvote 0
The "B65" is causing the error. Excel is looking for a column number, and while "B" will work, Excel can't convert the columun number of column "B65". If you want to get the last row in column B, change to "B" or just the number 2.


Tim
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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