Copy/Paste VBA error "subscript out of range"

aliciajo

New Member
Joined
Jul 19, 2013
Messages
2
I am trying to have someone enter a number and then it will open another excel document search for that number and then copy the row that number is in and paste everythig in that row to "Clean" which is the row that the user tells it to paste it in, in the original excel workbook. My code works fine until the copy and paste part. It then says "Subscript out of range". I have watched all my variables and they have the numbers I want and the ranges are the same size in both workbooks. I posted the code below and any help is appreciated.

Private Sub CommandButton1_Click()
Dim Charge As String, CellValue As String
Dim i As Single, j As Single, loc As Single, Clean As Single

Charge = InputBox("Charge Number?")
Clean = InputBox("Please enter the row where you want the information placed?")

Application.ScreenUpdating = False
Workbooks.Open ("P:\Common\Production\p300\Lime tanks\Lime Pit Inventory 2013.xlsx")
i = 1
For j = i To 130
CellValue = ActiveSheet.Range("C" & i).Value
If CellValue = Charge Then loc = i
i = i + 1
Next

Works fine untill line below:
Workbooks("P:\Common\Production\p300\Lime tanks\Lime Pit Inventory 2013.xlsx"). _
Worksheets("7.15.13"). _
Range("B" & loc, "AJ" & loc).Copy _
Destination:= _
Workbooks("C:\Documents and Settings\prodintern\My Documents\Summer '13\Pull Lime Tank Data.xlsm"). _
Worksheets("Sheet1"). _
Range("B" & Clean, "AJ" & Clean)

Workbooks("P:\Common\Production\p300\Lime tanks\Lime Pit Inventory 2013.xlsx").Close
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Subscript out of range results from misspelled words, missing or additional symbols, incorrect path, wrong file extension or just plain ain't there. One character can be the cause of the error, so the code has to be scrutinized very carefully.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,967
Messages
6,157,129
Members
451,399
Latest member
alchavar

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