Hello.
I'm a rookie to macros/VBA and to this website/forum. I appreciate any help I can get on my question (a rookie question).
I'm slogging my way through a macro that essentially copies specific (but non-continuous) columns of raw data from one worksheet ("data") to another worksheet ("fundings"). Both worksheets are in the same workbook. The code I listed below works (albeit, it is ugly), but I'm having a hard time pasting my data differently than how I'm copying it. What I need to do is paste the data into specific (non-continuous) columns on the destination worksheet. I'm using the Union function to copy the non-continuous columns from the raw data. This function combines the non-continuous columns and makes them look continuous. There are nine columns selected in "data" (see code below), and this data is then pasted to the first nine columns in "fundings". What I need to do is paste the results in specific columns of the destination worksheet ("fundings"). For example, I want the first-through-fourth copied columns ("A-D") to paste to the first four columns of the destination sheet (this already happens), and I want the fifth column of copied data ("G") to paste to the seventh column of the destination sheet (not working). I can't figure out how to skip columns in the pasting function.
Apologies for being lengthy. And thanks in advance for the help.
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim LDateToday As Date
Dim DestinationSheetName As String
Dim Fundings As String
Dim CopyToRow As Integer
'Macro is run based on the date that is listed on the "Company Statistics" tab.
LDateToday = Sheets("Company Statistics").Range("D1").Value
'Set the tab to where the data will be imported (from the "data" tab).
'Make sure to change this number if the "destination" row changes.
CopyToRowFundings = 13
'Select the row from which the macro starts searching for the relevant data (in the "data" tab).
LSearchRow = 2
'Select the worksheet from which the macro will pull the data (pulling from the "data" tab).
Sheets("Data").Select
'Only reference data in the respective column/row if there is a relevant data set available (e.g., refer to a code ID).
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'Set constraints to limit the amount of data searched by the macro.
'Refer to two tests for this function: a) the funding date compared to the relevant date, and b) the funding column has available data.
If (Range("U" & CStr(LSearchRow)).Value) < LDateToday And (Range("U" & CStr(LSearchRow)).Value) > 0 Then
'Select the specific columns on the data sheet to copy.
'Important to note that the first range covers columns A-D and the balance are individual columns.
Union(Range("A" & CStr(LSearchRow), "D" & CStr(LSearchRow)), Range("G" & CStr(LSearchRow)), Range("J" & CStr(LSearchRow)), Range("U" & CStr(LSearchRow)), Range("Y" & CStr(LSearchRow)), Range("AI" & CStr(LSearchRow))).Select
'Copy the specific columns as a continuous set of numbers, as if the columns were immediately next to each other (which explains the Union).
Selection.Copy
'Set the rules for matching the above data to the destination worksheet.
'The "+1" feature creates the loop.
'The "DestinationSheetName" feature points the data to the correct worksheet.
'Now we have copied the data, pointed it to the correct destination.
CopyToRow = CopyToRowFundings
CopyToRowFundings = CopyToRowFundings + 1
DestinationSheetName = "Fundings"
'Now tell the macro how to paste the data to its destination.
Sheets(DestinationSheetName).Select
Rows(CStr(CopyToRow) & ":" & CStr(CopyToRow)).Select
ActiveSheet.Paste
Bookmarks