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
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