Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel - copy row range based on cell value

Status
Not open for further replies.

cc4mail

Technical User
Jan 8, 2002
47
US
This has come up a few times in the forum without an answer (eg thread68_412048). I have the same problem.

Based on a cell value on sheet1, I want to copy a specific row range on sheet2 to sheet1 at a selected location.

The logic is correct, but I'm having a problem with the range. Can u help?

I want to call CopyRow onChange of specific cells on sheet1
(b21,b23,b25,b27,b29) and replace rows relative to the changed cell..



Sub CopyRow()
Dim varRow As Integer
Dim varCol As Integer
Dim varSel As Integer

varRow = Selection.row
varSel = Selection.Value
varCol = 3

' valid values 1 thru 7

Worksheets("Sheet2").Select
Select Case varSel
Case 1
Worksheets("Sheet2").Range("B6", "AD6").Copy
Case 2
Worksheets("Sheet2").Range("B8", "AD8").Copy
Case 3
Worksheets("Sheet2").Range("B10", "AD10").Copy
Case 4
Worksheets("Sheet2").Range("B12", "ADd12").Copy
Case 5
Worksheets("Sheet2").Range("B14", "AD14").Copy
Case 6
Worksheets("Sheet2").Range("B16", "AD16").Copy
Case 7
Worksheets("Sheet2").Range("B18", "AD18").Copy
Case Else
MsgBox ("Incorrect value")
End Select

Worksheets("Sheet1").Select
Worksheets("Sheet1").Cells(varRow + 1, varCol).Select
Worksheets("Sheet1").Paste
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top