PDA

View Full Version : [SOLVED:] Copy Data based on cell value



ericb1988
06-16-2016, 04:40 PM
I need help in copying 7000 rows. I have a list of numbers in sheet2 from B1:B100000 and I would like copy a spefic range based on a cell value in sheet 1 paste it to sheet 3.
For example, In sheet1 a1 has number 1000, and b1 has number 8000. I would like to copy that range b1000:b8000 in sheet 2 and paste it to sheet 3.
Thanks for any help with this

mancubus
06-17-2016, 12:23 AM
all macros below will copy or assign value of a range to a range in Sheet3, starting at A1.


Sub vbax_56354_copy_paste_based_on_input_range()

Dim StartRow As Long, EndRow As Long

With Worksheets("Sheet1")
StartRow = .Range("A1").Value
EndRow = .Range("B1").Value
End With

Worksheets("Sheet2").Range("B" & StartRow & ":B" & EndRow).Copy
Worksheets("Sheet3").Range("A1").PasteSpecial
Application.CutCopyMode = False

End Sub



Sub vbax_56354_copy_paste_based_on_input_range_noVariables()

Worksheets("Sheet2").Range("B" & Worksheets("Sheet1").Range("A1").Value & ":B" & Worksheets("Sheet1").Range("B1").Value).Copy
Worksheets("Sheet3").Range("A1").PasteSpecial
Application.CutCopyMode = False

End Sub




Sub vbax_56354_assign_value_based_on_input_range()

Dim StartRow As Long, EndRow As Long, NumRows As Long

With Worksheets("Sheet1")
StartRow = .Range("A1").Value
EndRow = .Range("B1").Value - .Range("A1").Value
NumRows = .Range("B1").Value - .Range("A1").Value + 1
End With

Worksheets("Sheet3").Range("A1").Resize(NumRows).Value = Worksheets("Sheet2").Range("B" & StartRow & ":B" & EndRow).Value

End Sub




Sub vbax_56354_assign_value_based_on_input_range_OneLiner()

Worksheets("Sheet3").Range("A1").Resize(Worksheets("Sheet1").Range("B1").Value - Worksheets("Sheet1").Range("A1").Value + 1).Value = Worksheets("Sheet2").Range("B" & Worksheets("Sheet1").Range("A1").Value & ":B" & Worksheets("Sheet1").Range("B1").Value)

End Sub

ericb1988
06-17-2016, 08:19 AM
Thanks for your help. That worked great.

mancubus
06-17-2016, 02:44 PM
you are welcome.
thanks for the feedback and marking the thread as solved.