dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I wish to copy a defined range---G2:G12000 from sheet1 into D2:D12000 on sheet2. Sounds simple right? However, Sheet 1 arrives each day with an inconsistent column order: Column G (sheet1) is sometimes Column D, Column H or Column J etc. Problematically, the header name is not consistent either, preventing me from using that as an identifier. However, the row range in sheet1 I wish to copy is always the same (2:12000), also, the destination range is always the same (Sheet 2, range D2:D12000).
Is it possible via VBA to stipulate the column letter using an InputBox and have the VBA do the below copy/paste function?
I haven't been able to find an example similar to this online.
Please would you help me modify the copy/paste code or suggest a method to achieve this?
Kind regards,
Doug.
P.S.
I have already tried using this macro
However, there are lots of blank cells in my CopyFrom range. The macro runs but doesn't paste any data.
I wish to copy a defined range---G2:G12000 from sheet1 into D2:D12000 on sheet2. Sounds simple right? However, Sheet 1 arrives each day with an inconsistent column order: Column G (sheet1) is sometimes Column D, Column H or Column J etc. Problematically, the header name is not consistent either, preventing me from using that as an identifier. However, the row range in sheet1 I wish to copy is always the same (2:12000), also, the destination range is always the same (Sheet 2, range D2:D12000).
Is it possible via VBA to stipulate the column letter using an InputBox and have the VBA do the below copy/paste function?
Code:
Sub SelectCustPORefCol()' SelectCustRef Macro
Worksheets("Sheet1").Activate
Sheets("Sheet2").Range("D2:D12000").Value = Sheets("Sheet1").Range("G2:G12000").Value
Sheets("Sheet2").Select
End Sub
I haven't been able to find an example similar to this online.
Please would you help me modify the copy/paste code or suggest a method to achieve this?
Kind regards,
Doug.
P.S.
I have already tried using this macro
Code:
Sub sample()
Dim rngToCopyFrom As Range, rngToPasteTo As Range
Set rngToCopyFrom = Application.InputBox("Selct first cell(s) to copy from", Type:=8)
If rngToCopyFrom Is Nothing Then Exit Sub
Set rngToCopyFrom = Rows(rngToCopyFrom.Row & ":" & ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row)
Set rngToPasteTo = Application.InputBox("Select first cell(s) to paste to", Type:=8)
If rngToPasteTo Is Nothing Then Exit Sub
rngToCopyFrom.Copy Rows(rngToPasteTo.Row).Cells(1, 1)
End Sub
However, there are lots of blank cells in my CopyFrom range. The macro runs but doesn't paste any data.