Doubt selecting completed cells as RANGE

Gopalakrishnan

Board Regular
Joined
Feb 19, 2013
Messages
110
From my worksheet, I just wanted to copy completed cells from used range (** used columns) which would have more than 100 rows but minimum 5 or 10 cells only would contain values. Here I wanted to copy those completed values from activesheet and need to paste another book. Already I have designed code for pasting and other stuffs but got struck up with selecting completed cells. Below is code I designed to do that job and with this I'm getting subscript out of range error while running, please do the require! :rolleyes:

Code:
Sub DeleteEmptyRow1(File)
Dim i, j, k As Integer
Dim LR, LC As Integer
Workbooks(File).Activate
LC = ActiveSheet.UsedRange.Columns.Count
LR = ActiveSheet.UsedRange.Rows.Count
For i = LC To 1 Step -1
If ActiveSheet.Cells(1, i).Value = "DESIGNNOTE" Then
'If cri2 = 1 Then
For j = LR To 1 Step -1
If ActiveSheet.Cells(j, i).Value = "" Then
Else
k = i - 1
Range(Cells(j, k), Cells(j, i)).Select ' I'm getting error @ this line only
ThisWorkbook.Sheets("Sheet2").Activate
MsgBox "Entering into loop"
ActiveSheet.Range("A1").PasteSpecial
End If
Next
End If
Next
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi Gopala,

This is working absolutely fine in my system. Excel 2010. Also I have added a line after "Range(Cells(j, k), Cells(j, i)).Select" which is Selection.Copy.

The results are pasted in sheet2 succesfully. I don't know why it is not working on your machine. Try this code on some other machine.

Regards...
 
Upvote 0
also k could possibly resolve to 0 (= i - 1, where i could be 1), which would error on your line
 
Upvote 0
Also it should be

Code:
Dim i As Long, j As Long, k As Long
Dim LR As Long, LC As Long
 
Upvote 0
Thanks everyone,,,,, it worked! I just changed the variable declaration to LONG and it resulted in successful design:)
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

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